author | Claus Gittinger <cg@exept.de> |
Sun, 12 May 1996 16:47:30 +0200 | |
changeset 1381 | c920ec16a98f |
parent 1375 | f035bb7468f5 |
child 1388 | e47b4b894530 |
permissions | -rw-r--r-- |
64 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 3 |
All Rights Reserved |
64 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
255 | 13 |
ByteArray subclass:#CharacterArray |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
14 |
instanceVariableNames:'' |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
15 |
classVariableNames:'PreviousMatch DecoderTables EncoderTables' |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
16 |
poolDictionaries:'' |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
17 |
category:'Collections-Text' |
64 | 18 |
! |
19 |
||
255 | 20 |
!CharacterArray class methodsFor:'documentation'! |
64 | 21 |
|
82 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
154 | 25 |
All Rights Reserved |
82 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
64 | 36 |
documentation |
37 |
" |
|
255 | 38 |
CharacterArray is a superclass for all kinds of Strings (i.e. |
68 | 39 |
(singleByte-)Strings, TwoByteStrings and whatever comes in the future. |
154 | 40 |
|
41 |
As the name already implies, this class is abstract, meaning that there are |
|
42 |
no instances of it. All this class does is provide common protocol for |
|
43 |
concrete subclasses. |
|
1290 | 44 |
|
45 |
[author:] |
|
46 |
Claus Gittinger |
|
47 |
||
48 |
[see also:] |
|
49 |
String TwoByteString |
|
50 |
StringCollection |
|
64 | 51 |
" |
52 |
! ! |
|
53 |
||
255 | 54 |
!CharacterArray class methodsFor:'instance creation'! |
64 | 55 |
|
56 |
basicNew |
|
57 |
"return a new empty string" |
|
58 |
||
59 |
^ self basicNew:0 |
|
60 |
! |
|
61 |
||
62 |
fromString:aString |
|
63 |
"return a copy of the argument, aString" |
|
64 |
||
68 | 65 |
^ (self basicNew:(aString size)) replaceFrom:1 with:aString |
66 |
||
67 |
"TwoByteString fromString:'hello'" |
|
581 | 68 |
! |
69 |
||
70 |
fromStringCollection:aCollectionOfStrings |
|
71 |
"return new string formed by concatenating a copy of the argument, aString" |
|
72 |
||
73 |
^ self fromStringCollection:aCollectionOfStrings separatedBy:'' |
|
74 |
||
75 |
" |
|
76 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') |
|
77 |
" |
|
78 |
||
79 |
"Created: 20.11.1995 / 15:26:59 / cg" |
|
80 |
! |
|
81 |
||
82 |
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString |
|
83 |
"return new string formed by concatenating a copy of the argument, aString" |
|
84 |
||
85 |
|newString first| |
|
86 |
||
87 |
newString := ''. |
|
88 |
first := true. |
|
89 |
aCollectionOfStrings do:[:s | |
|
90 |
first ifFalse:[ |
|
91 |
newString := newString , aSeparatorString |
|
92 |
] ifTrue:[ |
|
93 |
first := false |
|
94 |
]. |
|
95 |
newString := newString , s |
|
96 |
]. |
|
97 |
^ newString |
|
98 |
||
99 |
" |
|
100 |
String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' ' |
|
101 |
" |
|
102 |
||
103 |
"Created: 20.11.1995 / 15:32:17 / cg" |
|
608 | 104 |
! |
105 |
||
106 |
new |
|
107 |
"return a new empty string" |
|
108 |
||
109 |
^ self basicNew:0 |
|
64 | 110 |
! ! |
111 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
112 |
!CharacterArray class methodsFor:'cleanup'! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
113 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
114 |
lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
115 |
"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
|
116 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
117 |
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
|
118 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
119 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
120 |
CharacterArray lowSpaceCleanup |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
121 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
122 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
123 |
"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
|
124 |
"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
|
125 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
126 |
|
443 | 127 |
!CharacterArray class methodsFor:'code tables'! |
128 |
||
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
129 |
classForEncoding:encodingSymbol |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
130 |
"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
|
131 |
by encodingSymbol" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
132 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
encodingSymbol == #gb ifTrue:[^ GBEncodedString]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
136 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
137 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
138 |
"/ 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
|
139 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
140 |
^ String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
141 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
142 |
"Modified: 17.4.1996 / 16:18:53 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
143 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
144 |
|
443 | 145 |
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
|
146 |
"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
|
147 |
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
|
148 |
This is an experimental interface - unfinished" |
443 | 149 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
150 |
|table unrepresentableCharacterCode x80Table| |
443 | 151 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
152 |
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
|
153 |
table := DecoderTables at:encoding ifAbsent:nil. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
154 |
table notNil ifTrue:[^ table]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
155 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
156 |
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
|
157 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
158 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
159 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
160 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
161 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
162 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
163 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
164 |
"/ |
443 | 165 |
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
|
166 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
167 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
168 |
"/ mac -> iso8859 |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
169 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
170 |
"/ You will loose the following characters: |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
171 |
"/ - all of them will be replaced by 8F (¿) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
172 |
"/ |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
173 |
"/ A0 (dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
174 |
"/ A5 (dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
175 |
"/ AA (tm - trademark) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
176 |
"/ AD (not equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
177 |
"/ B0 (infinity) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
178 |
"/ B3 (less-double-equal <=) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
179 |
"/ B4 (greater-equal >-) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
180 |
"/ B6 (math lowercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
181 |
"/ B7 (math sum) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
182 |
"/ B8 (math uppercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
183 |
"/ B9 (math lowercase pi) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
184 |
"/ BA (math integral) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
185 |
"/ BD (math omega) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
186 |
"/ C3 (math union) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
187 |
"/ C4 (ext latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
188 |
"/ C5 (math almost equal) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
189 |
"/ C6 (math uppercase delta) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
190 |
"/ C9 (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
191 |
"/ CE (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
192 |
"/ CF (oe ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
193 |
"/ D1 (hyphen) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
194 |
"/ D2 (opening top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
195 |
"/ D3 (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
196 |
"/ D4 (opening top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
197 |
"/ D5 (closing top quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
198 |
"/ D7 (geometric: ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
199 |
"/ D9 (uppercase Y diacrit ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
200 |
"/ DA (slash2 ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
201 |
"/ DC (single oldStyle opening quote (<) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
202 |
"/ DD (single oldStyle closing quote (>) ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
203 |
"/ DE (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
204 |
"/ DF (? ) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
205 |
"/ E0 (double dagger ) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
206 |
"/ E2 (opening bottom quote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
207 |
"/ E3 (opening bottom dquote ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
208 |
"/ F0 (? ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
209 |
"/ F5 (latin l ) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
210 |
"/ F6 (diacrit circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
211 |
"/ F7 (diacrit tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
212 |
"/ F8 (diacrit top line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
213 |
"/ F9 (diacrit inverse circumflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
214 |
"/ FA (diacrit dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
215 |
"/ FB (diacrit ring) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
216 |
"/ FC (diacrit cedille left) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
217 |
"/ FD (diacrit dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
218 |
"/ FE (diacrit cedille right) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
219 |
"/ FF (diacrit circumflex2 ?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
220 |
"/ |
443 | 221 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
222 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
223 |
#( 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
|
224 |
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
|
225 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
226 |
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
|
227 |
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
|
228 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
229 |
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
|
230 |
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
|
231 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
235 |
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
|
236 |
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
|
237 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
244 |
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
|
245 |
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
|
246 |
). |
657 | 247 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
248 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
249 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
250 |
"/ next -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
251 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
252 |
"/ You will loose the following characters: |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
253 |
"/ - all of them will be replaced by 8F (¿) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
254 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
255 |
"/ A4 (diacrit /) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
256 |
"/ A9 (diacrit quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
257 |
"/ AA (top opening dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
258 |
"/ AC (single oldStyle opening quote (<)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
259 |
"/ AD (single oldStyle closing quote (>)) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
260 |
"/ AE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
261 |
"/ AF (?) |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
262 |
"/ B2 (dagger) |
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
263 |
"/ B3 (double dagger) |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
264 |
"/ B7 (enter dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
265 |
"/ B8 (opening bottom quote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
266 |
"/ B9 (opening bottom dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
267 |
"/ BA (closing top dquote) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
268 |
"/ BC (dot-dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
269 |
"/ BD (per-mille) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
270 |
"/ C0 (subscript 1) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
271 |
"/ C1 (accent grave) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
272 |
"/ C2 (accent degu) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
273 |
"/ C3 (accent circonflex) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
274 |
"/ C4 (accent tilde) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
275 |
"/ C5 (accent line) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
276 |
"/ C6 (accent circonflex reverse) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
277 |
"/ C7 (accent dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
278 |
"/ C8 (accent dot-dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
279 |
"/ D0 (hline) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
280 |
"/ 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
|
281 |
"/ EA (OE ligature) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
282 |
"/ F5 (latin l) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
283 |
"/ 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
|
284 |
"/ FE (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
285 |
"/ FF (?) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
286 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
287 |
encoding == #next ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
288 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
289 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
290 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
291 |
#( 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
|
292 |
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
|
293 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
303 |
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
|
304 |
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
|
305 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
315 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
316 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
317 |
"/ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
318 |
"/ msdos (codePage 437) -> iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
319 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
320 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
321 |
"/ You will loose the following characters: |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
322 |
"/ - all of them will be replaced by 8F (¿) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
323 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
324 |
"/ 9E (pesetas) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
325 |
"/ 9F (latin f) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
326 |
"/ A9 (technical not) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
327 |
"/ B0 - BF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
328 |
"/ C0 - CF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
329 |
"/ D0 - DF (block graphic) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
330 |
"/ E0 (greek alpha) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
331 |
"/ E2 - E5 (greek) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
332 |
"/ E7 - EC (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
333 |
"/ EE - EF (greek & math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
334 |
"/ F0 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
335 |
"/ F2 - F5 (math & technical) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
336 |
"/ F7 (math) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
337 |
"/ F9 (center dot) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
338 |
"/ FB (math sqrt) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
339 |
"/ FC (super n) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
340 |
"/ 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
|
341 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
342 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
343 |
unrepresentableCharacterCode := 16rBF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
344 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
345 |
x80Table := |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
346 |
#( 16r00c7 16r00fc 16r00e9 16r00e2 16r00e4 16r00e0 16r00e5 16r00e7 "/ 80 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
347 |
16r00ea 16r00eb 16r00e8 16r00ef 16r00ee 16r00ec 16r00c4 16r00c5 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
348 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
349 |
16r00c9 16r00e6 16r00c6 16r00f4 16r00f6 16r00f2 16r00fb 16r00f9 "/ 90 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
350 |
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
|
351 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
352 |
16r00e1 16r00ed 16r00f3 16r00fa 16r00f1 16r00d1 16r00aa 16r00da "/ a0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
353 |
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
|
354 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
361 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF "/ d0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
362 |
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
|
363 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
364 |
16rFFFF 16r00df 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00b5 16rFFFF "/ e0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
365 |
16rFFFF 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f8 16rFFFF 16rFFFF |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
366 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
367 |
16rFFFF 16r00b1 16rFFFF 16rFFFF 16rFFFF 16rFFFF 16r00f7 16rFFFF "/ f0 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
368 |
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
|
369 |
). |
443 | 370 |
]. |
371 |
"/ more encodings needed here .... |
|
372 |
||
1250
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 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
375 |
"/ 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
|
376 |
"/ 0x80..0xFF characters |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
377 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
378 |
x80Table notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
379 |
x80Table keysAndValuesDo:[:idx :repl | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
380 |
|ch| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
381 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
382 |
repl == 16rFFFF ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
383 |
ch := unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
384 |
] ifFalse:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
385 |
ch := repl |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
386 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
387 |
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
|
388 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
389 |
]. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
390 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
391 |
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
|
392 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
393 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
394 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
395 |
DecoderTables := nil |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
396 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
397 |
|
443 | 398 |
"Created: 20.10.1995 / 23:04:43 / cg" |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
399 |
"Modified: 23.4.1996 / 20:20:32 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
400 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
401 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
402 |
encoderTableFor:encoding |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
403 |
"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
|
404 |
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
|
405 |
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
|
406 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
407 |
|table decoderTable unrepresentableCharacterCode |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
408 |
unrepresentableISOCharacterCode x80Table| |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
409 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
410 |
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
|
411 |
table := EncoderTables at:encoding ifAbsent:nil. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
412 |
table notNil ifTrue:[^ table]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
413 |
] ifFalse:[ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
414 |
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
|
415 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
416 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
417 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
418 |
"/ iso8859 -> mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
419 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
420 |
encoding == #mac ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
421 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
422 |
unrepresentableCharacterCode := 16rFF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
423 |
unrepresentableISOCharacterCode := 16rBF. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
424 |
]. |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
425 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
426 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
427 |
"/ iso8859 -> msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
428 |
"/ |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
429 |
encoding == #msdos ifTrue:[ |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
430 |
decoderTable := self decoderTableFor:encoding. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
431 |
unrepresentableCharacterCode := 16rFF. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
432 |
unrepresentableISOCharacterCode := 16rBF. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
433 |
]. |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
434 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
435 |
"/ 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
|
436 |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
437 |
decoderTable notNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
438 |
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
|
439 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
440 |
0 to:16rFF do:[:code | |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
441 |
|isoCode destIdex| |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
442 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
443 |
isoCode := decoderTable at:(code+1). |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
444 |
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
|
445 |
] |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
446 |
]. |
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 |
table isNil ifTrue:[ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
449 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
450 |
"/ setup as identityTranslation |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
451 |
"/ |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
452 |
table := (0 to:255) asByteArray. |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
453 |
]. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
454 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
455 |
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
|
456 |
^ table |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
457 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
458 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
459 |
EncoderTables := nil |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
460 |
DecoderTables := nil |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
461 |
CharacterArray decoderTableFor:#mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
462 |
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
|
463 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
464 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
465 |
"Created: 22.2.1996 / 16:17:58 / cg" |
1272
b45ddd6d6ec3
assume printer can handle ISO-latin1 encoded strings (national characters)
Claus Gittinger <cg@exept.de>
parents:
1255
diff
changeset
|
466 |
"Modified: 23.4.1996 / 20:20:42 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
467 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
468 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
469 |
supportedEncodings |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
470 |
"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
|
471 |
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
|
472 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
473 |
^ #( |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
474 |
( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
475 |
iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
476 |
ascii |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
477 |
msdos |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
478 |
mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
479 |
next |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
480 |
euc |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
481 |
jis |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
482 |
jis7 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
483 |
gb |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
484 |
big5) |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
485 |
) |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
486 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
487 |
"Created: 22.2.1996 / 16:19:20 / cg" |
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
488 |
"Modified: 22.4.1996 / 14:43:50 / cg" |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
489 |
! |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
490 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
491 |
supportedExternalEncodings |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
492 |
"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
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
498 |
^ #( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
499 |
( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
500 |
'iso8859 (ansi)' |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
501 |
'msdos (codepage 437)' |
1255 | 502 |
'macintosh (8 bit)' |
503 |
'NEXT (8 bit)' |
|
504 |
'EUC (extended unix code japanese)' |
|
505 |
'JIS7 (jis 7bit escape codes japanese)' |
|
506 |
'GB (mainland china)' |
|
507 |
'BIG5 (taiwan)' |
|
1250
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
508 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
509 |
( |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
510 |
iso8859 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
511 |
msdos |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
512 |
mac |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
513 |
next |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
514 |
euc |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
515 |
jis7 |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
516 |
gb |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
517 |
big5) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
518 |
) |
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
519 |
|
0f628432aa93
fixed encoding/decoding for msdos & mac; added next decoder
Claus Gittinger <cg@exept.de>
parents:
1241
diff
changeset
|
520 |
"Created: 22.4.1996 / 14:39:39 / cg" |
1255 | 521 |
"Modified: 22.4.1996 / 16:40:51 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
522 |
! ! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
523 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
524 |
!CharacterArray class methodsFor:'encoding / decoding'! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
525 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
526 |
decodeFromBIG5:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
527 |
"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
|
528 |
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
|
529 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
530 |
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
|
531 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
532 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
533 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
534 |
newString := BIG5EncodedString new:aString size. |
1204 | 535 |
^ self decodeFromBIG5_or_GB:aString into:newString. |
536 |
||
537 |
"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
|
538 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
539 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
540 |
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
|
541 |
"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
|
542 |
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
|
543 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
544 |
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
|
545 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
546 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
547 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
548 |
srcIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
549 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
550 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
551 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
552 |
c| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
553 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
554 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
555 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
556 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
557 |
srcIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
558 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
559 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
560 |
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
|
561 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
562 |
"/ characters below 16rA1 are left untranslated |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
563 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
564 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
565 |
b1 >= 16rA1 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
566 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
567 |
srcIdx <= sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
572 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
573 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
574 |
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
|
575 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
576 |
srcIdx := srcIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
577 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
578 |
srcIdx > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
579 |
^ 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
|
580 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
581 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
582 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
583 |
^ a16BitString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
584 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
585 |
"Created: 17.4.1996 / 16:55:54 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
586 |
"Modified: 17.4.1996 / 18:28:31 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
587 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
588 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
589 |
decodeFromEUC:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
590 |
"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
|
591 |
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
|
592 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
593 |
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
|
594 |
this one only understands New-JIS. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
595 |
The result is a JISEncodedString (you need a JIS 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
|
596 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
597 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
598 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
599 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
600 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
601 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
602 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
603 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
604 |
romans c| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
605 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
606 |
romans := JISEncodedString romanJISDecoderTable. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
607 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
608 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
609 |
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
|
610 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
611 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
612 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
613 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
614 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
615 |
c := aString at:start. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
616 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
617 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
618 |
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
|
619 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
620 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
621 |
b1 < 161 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
622 |
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
|
623 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
624 |
"/ b1 < 127 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
625 |
"/ newString at:dstIdx put:(Character value:(romans at:(b1 - 32))). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
626 |
"/ dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
627 |
"/ ] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
628 |
"/ self halt:'unsupported codeSet' |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
629 |
"/ ] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
630 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
631 |
start := start + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
632 |
b1 := b1 - 161 + 33. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
633 |
b2 := (aString at:start) asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
634 |
b2 := b2 - 161 + 33. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
635 |
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
|
636 |
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
|
637 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
638 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
639 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
640 |
start := start + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
641 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
642 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
643 |
^ 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
|
644 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
645 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
646 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
647 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
648 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
649 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
650 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
651 |
'hello' decodeFromEUC |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
652 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
653 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
654 |
"Created: 17.4.1996 / 16:10:22 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
655 |
"Modified: 17.4.1996 / 16:48:30 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
656 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
657 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
658 |
decodeFromGB:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
659 |
"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
|
660 |
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
|
661 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
662 |
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
|
663 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
664 |
|newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
665 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
666 |
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
|
667 |
^ 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
|
668 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
669 |
"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
|
670 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
671 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
672 |
decodeFromJIS7:aString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
673 |
"return a new string containing the aStrings characters, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
674 |
which are interpreted as a JIS7 encoded singleByte string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
675 |
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
|
676 |
this one understands New-JIS and treats Old-JIS just the same. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
677 |
The result is a JISEncodedString (you need a JIS 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
|
678 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
679 |
|newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
680 |
sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
681 |
dstIdx "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
682 |
start "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
683 |
stop "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
684 |
n1 n2 n3 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
685 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
686 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
687 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
688 |
singleBytes romans| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
689 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
690 |
romans := JISEncodedString romanJISDecoderTable. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
691 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
692 |
sz := aString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
693 |
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
|
694 |
sz ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
695 |
dstIdx := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
696 |
start := 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
697 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
698 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
699 |
[true] whileTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
700 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
701 |
"/ 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
|
702 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
703 |
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
|
704 |
stop == 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
705 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
706 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
707 |
(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
|
708 |
stop := sz + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
709 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
710 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
711 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
712 |
start to:(stop - 1) do:[:i | |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
713 |
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
|
714 |
newString at:dstIdx put:(Character value:b1). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
715 |
"/ (b1 < 33 or:[b1 > 191]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
716 |
"/ newString at:dstIdx put:(Character value:b1) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
717 |
"/ ] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
718 |
"/ newString at:dstIdx put:(Character value:(romans at:(b1 - 32))) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
719 |
"/ ]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
720 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
721 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
722 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
723 |
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
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
dstIdx := dstIdx + 1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
729 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
730 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
731 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
732 |
stop > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
733 |
^ 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
|
734 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
735 |
start := stop. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
736 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
737 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
738 |
"/ 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
|
739 |
"/ - 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
|
740 |
"/ 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
|
741 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
742 |
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
|
743 |
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
|
744 |
n3 := aString at:(start + 2). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
745 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
746 |
(n2 == $$ and:[n3 == $B]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
747 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
748 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
749 |
(n2 == $$ and:[n3 == $@]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
750 |
singleBytes := false. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
751 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
752 |
(n2 == $( and:[n3 == $B]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
753 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
754 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
755 |
(n2 == $( and:[n3 == $J]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
756 |
singleBytes := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
757 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
758 |
singleBytes ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
759 |
newString at:dstIdx put:n1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
760 |
newString at:(dstIdx + 1) put:n2. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
761 |
newString at:(dstIdx + 2) put:n3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
762 |
dstIdx := dstIdx + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
763 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
764 |
self halt. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
765 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
766 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
767 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
768 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
769 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
770 |
start := start + 3. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
771 |
start > sz ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
772 |
^ 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
|
773 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
774 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
775 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
776 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
777 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
778 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
779 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
780 |
'hello' decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
781 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
782 |
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
|
783 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
784 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
785 |
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
|
786 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
787 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
788 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
789 |
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
|
790 |
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
|
791 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
792 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
793 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
794 |
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
|
795 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
796 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
797 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
798 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
799 |
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
|
800 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
801 |
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
|
802 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
803 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
804 |
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
|
805 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
806 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
807 |
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
|
808 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
809 |
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
|
810 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
811 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
812 |
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
|
813 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
814 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
815 |
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
|
816 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
817 |
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
|
818 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
819 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
820 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
821 |
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
|
822 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
823 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
824 |
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
|
825 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
826 |
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
|
827 |
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
|
828 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
829 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
830 |
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
|
831 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
832 |
|s| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
833 |
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
|
834 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
835 |
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
|
836 |
s := s , '$3'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
837 |
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
|
838 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
839 |
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
|
840 |
s := s , 'hello'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
841 |
s decodeFromJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
842 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
843 |
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
|
844 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
845 |
|s t l| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
846 |
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
|
847 |
s := s copyWith:$$. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
s := s copyWith:$(. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
852 |
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
|
853 |
s := s , ' kterm'. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
854 |
t := s decodeFromJIS7. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
855 |
l := Label new. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
856 |
l label:t. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
857 |
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
|
858 |
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
|
859 |
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
|
860 |
l realize |
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 |
"Modified: 2.3.1996 / 13:39:08 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
864 |
"Created: 17.4.1996 / 16:11:57 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
865 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
866 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
867 |
encodeIntoBIG5withRomans:aBIG5String |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
868 |
"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
|
869 |
The argument must be a BIG5String. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
870 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
871 |
This is used translate 8bit strings and pseudoBIG5 strings |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
872 |
(romans are left untranslated) into a real BIG5 encoding for drawing. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
873 |
Assuming, that the ascii codePage is at 16r2100. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
874 |
Doing this allows single-byte roman strings to be displayed in a BIG5 font." |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
875 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
876 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
877 |
b "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
878 |
c romans newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
879 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
880 |
romans := BIG5EncodedString romanBIG5DecoderTable. |
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 := aBIG5String size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
883 |
newString := BIG5EncodedString new:sz. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
884 |
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
|
885 |
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
|
886 |
b := c asciiValue. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
887 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
888 |
(b >= 33 and:[b <= (159+32)]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
889 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
890 |
"/ a roman character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
891 |
"/ map to corresponding BIG5 code |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
892 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
893 |
c := Character value:(romans at:b - 32). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
894 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
895 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
896 |
"/ control or a big5 character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
897 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
898 |
]. |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
899 |
|
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
900 |
newString at:index put:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
901 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
902 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
903 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
904 |
"Created: 17.4.1996 / 17:17:50 / cg" |
1203
a43528048cb8
code tables moved to BIG5/JISEncodedString classes
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
905 |
"Modified: 17.4.1996 / 18:55:40 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
906 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
907 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
908 |
encodeIntoEUC:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
909 |
"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
|
910 |
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
|
911 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
912 |
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
|
913 |
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
|
914 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
915 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
916 |
b1 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
917 |
b2 "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
918 |
val "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
919 |
romans out| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
920 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
921 |
romans := JISEncodedString romanJISDecoderTable. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
922 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
923 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
924 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
925 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
926 |
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
|
927 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
928 |
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
|
929 |
b1 := (aJISString at:srcIndex) asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
930 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
931 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
932 |
out nextPut:(Character value:b1). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
933 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
934 |
"/ 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
|
935 |
"/ 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
|
936 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
937 |
(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
|
938 |
val := romans indexOf:b1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
939 |
val ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
940 |
out nextPut:(Character value:(val - 1 + 33)) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
941 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
942 |
out nextPut:(Character value:(val bitShift:-8) - 33 + 161). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
943 |
out nextPut:(Character value:(val bitAnd:16rFF) - 33 + 161). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
944 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
945 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
946 |
out nextPut:(Character value:(val bitShift:-8) - 33 + 161). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
947 |
out nextPut:(Character value:(val bitAnd:16rFF) - 33 + 161). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
948 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
949 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
950 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
951 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
952 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
953 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
954 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
955 |
'hello' decodeFromEUC encodeIntoEUC |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
956 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
957 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
958 |
"Modified: 2.3.1996 / 13:40:12 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
959 |
"Created: 17.4.1996 / 16:13:33 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
960 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
961 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
962 |
encodeIntoGBwithRomans:aGBString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
963 |
"return a new string with aGBStrings characters as GB encoded 16bit string, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
964 |
The argument must be a GBString. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
965 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
966 |
This is used translate 8bit strings and pseudoGB5 strings |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
967 |
(romans are left untranslated) into a real GB encoding for drawing. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
968 |
Assuming, that the ascii codePage is at 16r2100. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
969 |
Doing this allows single-byte roman strings to be displayed in a GB font." |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
970 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
971 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
972 |
b "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
973 |
c newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
974 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
975 |
sz := aGBString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
976 |
newString := GBEncodedString new:sz. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
977 |
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
|
978 |
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
|
979 |
b := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
980 |
(b >= 33 and:[b <= (159+32)]) ifTrue:[ |
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 |
"/ a roman character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
983 |
"/ map to corresponding GB code |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
984 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
985 |
c := Character value:(16r2100 + b). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
986 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
987 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
988 |
"/ control or a gb character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
989 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
990 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
991 |
newString at:index put:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
992 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
993 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
994 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
995 |
"Modified: 17.4.1996 / 17:30:36 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
996 |
"Created: 17.4.1996 / 17:31:48 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
997 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
998 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
999 |
encodeIntoJIS7:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1000 |
"return a new string with aJISStrings characters as JIS7 encoded 7bit string, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1001 |
The receiver must be a 16bit JIS character string. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1002 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1003 |
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
|
1004 |
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
|
1005 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1006 |
|sz "{ Class:SmallInteger }" |
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 val romans out inSingleByteMode c kanji roman| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1009 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1010 |
inSingleByteMode := true. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1011 |
kanji := JISEncodedString jis7KanjiEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1012 |
roman := JISEncodedString jis7RomanEscapeSequence. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1013 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1014 |
romans := JISEncodedString romanJISDecoderTable. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1015 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1016 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1017 |
sz == 0 ifTrue:[^ '']. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1018 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1019 |
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
|
1020 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1021 |
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
|
1022 |
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
|
1023 |
b1 := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1024 |
b1 < 33 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1025 |
"/ a control character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1026 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1027 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1028 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1029 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1030 |
out nextPut:c. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1031 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1032 |
"/ 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
|
1033 |
"/ 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
|
1034 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1035 |
(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
|
1036 |
val := romans indexOf:b1. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1037 |
val ~~ 0 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1038 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1039 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1040 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1041 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1042 |
out nextPut:(Character value:(val - 1 + 33)) |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1043 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1044 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1045 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1046 |
inSingleByteMode := false |
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 |
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
|
1049 |
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
|
1050 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1051 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1052 |
b1 <= 255 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1053 |
"/ 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
|
1054 |
"/ b1 >= 160 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1055 |
"/ ('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
|
1056 |
"/ ]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1057 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1058 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1059 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1060 |
inSingleByteMode := true |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1061 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1062 |
out nextPut:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1063 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1064 |
inSingleByteMode ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1065 |
out nextPutAll:kanji. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1066 |
inSingleByteMode := false |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1067 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1068 |
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
|
1069 |
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
|
1070 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1071 |
] |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1072 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1073 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1074 |
inSingleByteMode ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1075 |
out nextPutAll:roman. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1076 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1077 |
^ out contents |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1078 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1079 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1080 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1081 |
'hello' decodeFromJIS7 encodeIntoJIS7 |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1082 |
" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1083 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1084 |
"Modified: 2.3.1996 / 13:40:31 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1085 |
"Created: 17.4.1996 / 16:17:40 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1086 |
! |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1087 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1088 |
encodeIntoJISwithRomans:aJISString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1089 |
"return a new string with aJISStrings characters as JIS encoded 16bit string, |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1090 |
The argument must be a JISString. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1091 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1092 |
This is used translate 8bit strings and pseudoJIS strings |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1093 |
(romans are left untranslated) into a real JIS encoding for drawing. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1094 |
Doing this allows single-byte roman strings to be displayed in a JIS font." |
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 |
|sz "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1097 |
b "{ Class: SmallInteger }" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1098 |
c romans newString| |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1099 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1100 |
romans := JISEncodedString romanJISDecoderTable. |
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 |
sz := aJISString size. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1103 |
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
|
1104 |
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
|
1105 |
c := aJISString at:index. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1106 |
b := c asciiValue. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1107 |
(b >= 33 and:[b <= (159+32)]) ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1108 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1109 |
"/ a roman character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1110 |
"/ map to corresponding JIS code |
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 |
c := Character value:(romans at:b - 32). |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1113 |
] ifFalse:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1114 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1115 |
"/ control or a kanji character |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1116 |
"/ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1117 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1118 |
newString at:index put:c |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1119 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1120 |
^ newString |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1121 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1122 |
"simple: |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1123 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1124 |
'hello' encodeIntoJIS |
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 |
|
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1127 |
"Created: 17.4.1996 / 17:15:23 / cg" |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
1128 |
"Modified: 17.4.1996 / 17:30:59 / cg" |
443 | 1129 |
! ! |
1130 |
||
328 | 1131 |
!CharacterArray class methodsFor:'pattern matching'! |
64 | 1132 |
|
327 | 1133 |
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase |
1134 |
"helper for match; return true if the characters from start to stop in |
|
1135 |
aString are matching the scan in matchScan from matchStart to matchStop. |
|
328 | 1136 |
The matchScan is as created by asMatchScanArray. |
327 | 1137 |
|
328 | 1138 |
This algorithm is not at all the most efficient; |
1139 |
for heavy duty pattern matching, an interface (primitive) to the regex |
|
1140 |
pattern matching package should be added." |
|
327 | 1141 |
|
1142 |
|matchEntry |
|
1143 |
mStart "{ Class: SmallInteger }" |
|
1144 |
mStop "{ Class: SmallInteger }" |
|
1145 |
sStart "{ Class: SmallInteger }" |
|
1146 |
sStop "{ Class: SmallInteger }" |
|
1147 |
mSize "{ Class: SmallInteger }" |
|
1148 |
sSize "{ Class: SmallInteger }" |
|
1149 |
index "{ Class: SmallInteger }" |
|
1150 |
quickCheck matchLast |
|
986 | 1151 |
checkChar included| |
327 | 1152 |
|
1153 |
mStart := matchStart. |
|
1154 |
mStop := matchStop. |
|
1155 |
sStart := start. |
|
1156 |
sStop := stop. |
|
1157 |
||
1158 |
[true] whileTrue:[ |
|
1159 |
mSize := mStop - mStart + 1. |
|
1160 |
sSize := sStop - sStart + 1. |
|
1161 |
||
1162 |
"empty strings match" |
|
1163 |
(mSize == 0) ifTrue:[^ (sSize == 0)]. |
|
1164 |
||
1165 |
matchEntry := matchScanArray at:mStart. |
|
1166 |
||
1167 |
"/ the most common case first: |
|
1168 |
(sSize ~~ 0 |
|
1169 |
and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[ |
|
1170 |
"advance by one and continue" |
|
1171 |
mStart := mStart + 1. |
|
1172 |
sStart := sStart + 1 |
|
1173 |
] ifFalse:[ |
|
1174 |
(matchEntry == #any) ifTrue:[ |
|
1175 |
"restString empty -> no match" |
|
1176 |
(sSize == 0) ifTrue:[^ false]. |
|
1177 |
"# matches single character" |
|
1178 |
((sSize == 1) and:[mSize == 1]) ifTrue:[^ true]. |
|
1179 |
"advance by one and continue" |
|
1180 |
mStart := mStart + 1. |
|
1181 |
sStart := sStart + 1 |
|
1182 |
] ifFalse:[ |
|
1183 |
(matchEntry == #anyString) ifTrue:[ |
|
1184 |
"* alone matches anything" |
|
1185 |
(mSize == 1) ifTrue:[^ true]. |
|
1186 |
"restString empty & matchString not empty -> no match" |
|
1187 |
(sSize == 0) ifTrue:[^ false]. |
|
1188 |
||
1189 |
" |
|
1190 |
try to avoid some of the recursion by checking last |
|
1191 |
character and continue with shortened strings if possible |
|
1192 |
" |
|
1193 |
quickCheck := false. |
|
1194 |
(mStop >= mStart) ifTrue:[ |
|
1195 |
matchLast := matchScanArray at:mStop. |
|
1196 |
(matchLast ~~ #anyString) ifTrue:[ |
|
1197 |
(matchLast == #any) ifTrue:[ |
|
1198 |
quickCheck := true |
|
1199 |
] ifFalse:[ |
|
1200 |
matchLast == (aString at:sStop) ifTrue:[ |
|
1201 |
quickCheck := true |
|
1202 |
] ifFalse:[ |
|
1203 |
matchLast isString ifTrue:[ |
|
1204 |
quickCheck := matchLast includes:(aString at:sStop) |
|
1205 |
] |
|
1206 |
] |
|
1207 |
] |
|
1208 |
] |
|
1209 |
]. |
|
1210 |
quickCheck ifFalse:[ |
|
1211 |
" |
|
1212 |
no quick check possible; |
|
1213 |
loop over all possible substrings |
|
1214 |
" |
|
1215 |
index := sStart. |
|
1216 |
[index <= sStop] whileTrue:[ |
|
1217 |
(self matchScan:matchScanArray |
|
1218 |
from:(mStart + 1) |
|
1219 |
to:mStop |
|
1220 |
with:aString |
|
1221 |
from:index |
|
1222 |
to:stop |
|
1223 |
ignoreCase:ignoreCase) ifTrue:[ |
|
1224 |
^ true |
|
1225 |
]. |
|
1226 |
index := index + 1 |
|
1227 |
]. |
|
1228 |
^ false |
|
1229 |
]. |
|
1230 |
" |
|
1231 |
quickCheck ok, advance from the right |
|
1232 |
" |
|
1233 |
mStop := mStop - 1. |
|
1234 |
sStop := sStop - 1 |
|
1235 |
] ifFalse:[ |
|
1236 |
(matchEntry isString) ifTrue:[ |
|
1237 |
"testString empty -> no match" |
|
1238 |
(sSize == 0) ifTrue:[^ false]. |
|
1239 |
||
1240 |
included := false. |
|
1241 |
"/ checkChar := aString at:sStart. |
|
1242 |
included := matchEntry includes:checkChar. |
|
1243 |
included ifFalse:[ |
|
1244 |
ignoreCase ifTrue:[ |
|
1245 |
checkChar isUppercase ifTrue:[ |
|
1246 |
included := matchEntry includes:checkChar asLowercase. |
|
1247 |
] ifFalse:[ |
|
1248 |
included := matchEntry includes:checkChar asUppercase. |
|
1249 |
] |
|
1250 |
]. |
|
1251 |
]. |
|
1252 |
mStart := mStart + 1. |
|
1253 |
mSize := mSize - 1. |
|
1254 |
included ifFalse:[^ false]. |
|
1255 |
||
1256 |
((sSize == 1) and:[mSize == 0]) ifTrue:[^ true]. |
|
1257 |
"cut off 1st char and continue" |
|
1258 |
sStart := sStart + 1 |
|
1259 |
] ifFalse:[ |
|
1260 |
"/ must be single character |
|
1261 |
||
1262 |
"testString empty ?" |
|
1263 |
(sSize == 0) ifTrue:[^ false]. |
|
1264 |
||
1265 |
"first characters equal ?" |
|
1266 |
"/ checkChar := aString at:sStart. |
|
1267 |
ignoreCase ifFalse:[^ false]. |
|
1268 |
(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false]. |
|
1269 |
||
1270 |
"advance and continue" |
|
1271 |
mStart := mStart + 1. |
|
1272 |
sStart := sStart + 1 |
|
1273 |
] |
|
1274 |
] |
|
1275 |
] |
|
1276 |
] |
|
1277 |
] |
|
608 | 1278 |
! |
1279 |
||
1280 |
matchScanArrayFrom:aString |
|
1281 |
"scan a pattern string and decompose it into a scanArray. |
|
1282 |
This is processed faster (especially with character ranges), and |
|
1283 |
can also be reused later. (if the same pattern is to be searched again)" |
|
1284 |
||
1285 |
|coll |
|
1286 |
idx "{ Class: SmallInteger }" |
|
1287 |
end c1 c2 matchSet previous| |
|
1288 |
||
1289 |
coll := OrderedCollection new. |
|
1290 |
idx := 1. end := aString size. |
|
1291 |
[idx <= end] whileTrue:[ |
|
1292 |
|char this| |
|
1293 |
||
1294 |
char := aString at:idx. |
|
1295 |
char == $* ifTrue:[ |
|
1296 |
previous ~~ #anyString ifTrue:[ |
|
1297 |
this := #anyString |
|
1298 |
] |
|
1299 |
] ifFalse:[ |
|
1300 |
char == $# ifTrue:[ |
|
1301 |
previous ~~ #anyString ifTrue:[ |
|
1302 |
this := #any |
|
1303 |
] |
|
1304 |
] ifFalse:[ |
|
1305 |
char == $[ ifTrue:[ |
|
1306 |
matchSet := IdentitySet new. |
|
1307 |
idx := idx + 1. |
|
1308 |
idx > end ifTrue:[^ nil]. |
|
1309 |
char := aString at:idx. |
|
1310 |
c1 := nil. |
|
1311 |
[char ~~ $]] whileTrue:[ |
|
1312 |
((char == $-) and:[c1 notNil]) ifTrue:[ |
|
1313 |
idx := idx + 1. |
|
1314 |
idx > end ifTrue:[^ nil]. |
|
1315 |
c2 := aString at:idx. |
|
828
a1922f7414ff
Replace subotimal (to:)do: with to:do:.
Stefan Vogel <sv@exept.de>
parents:
815
diff
changeset
|
1316 |
c1 to:c2 do:[:c | matchSet add:c]. |
608 | 1317 |
c1 := nil. |
1318 |
idx := idx + 1. |
|
1319 |
] ifFalse:[ |
|
1320 |
(char ~~ $]) ifTrue:[ |
|
1321 |
matchSet add:char. |
|
1322 |
c1 := char. |
|
1323 |
idx := idx + 1 |
|
1324 |
] |
|
1325 |
]. |
|
1326 |
idx > end ifTrue:[^ nil]. |
|
1327 |
char := aString at:idx |
|
1328 |
]. |
|
1329 |
this := matchSet asString |
|
1330 |
] ifFalse:[ |
|
1331 |
this := char |
|
1332 |
] |
|
1333 |
] |
|
1334 |
]. |
|
1335 |
this notNil ifTrue:[coll add:this. previous := this]. |
|
1336 |
idx := idx + 1 |
|
1337 |
]. |
|
1338 |
||
1339 |
^ coll asArray |
|
1340 |
||
1341 |
" |
|
1342 |
String matchScanArrayFrom:'*ute*' |
|
1343 |
String matchScanArrayFrom:'**ute**' |
|
1344 |
String matchScanArrayFrom:'*uter' |
|
1345 |
String matchScanArrayFrom:'[cC]#mpute[rR]' |
|
1346 |
String matchScanArrayFrom:'[abcd]*' |
|
1347 |
String matchScanArrayFrom:'[a-k]*' |
|
1348 |
String matchScanArrayFrom:'*some*compl*ern*' |
|
1349 |
String matchScanArrayFrom:'[a-' |
|
1350 |
String matchScanArrayFrom:'[a-zA-Z]' |
|
1351 |
String matchScanArrayFrom:'[a-z01234A-Z]' |
|
1352 |
" |
|
1353 |
! ! |
|
1354 |
||
1355 |
!CharacterArray methodsFor:'Compatibility - ST/V'! |
|
1356 |
||
1357 |
byteAt:index put:aByte |
|
1358 |
"store a byte at given index. |
|
1359 |
This is an ST/V compatibility method." |
|
1360 |
||
1333
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1361 |
"/ (aByte == 0) ifTrue:[ |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1362 |
"/ "store a space instead" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1363 |
"/ ^ 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
|
1364 |
"/ ]. |
608 | 1365 |
^ 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
|
1366 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1367 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1368 |
'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
|
1369 |
'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
|
1370 |
'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
|
1371 |
" |
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1372 |
|
d3fdca956f0d
allow storing of 0-bytes (be careful with printing then ...)
Claus Gittinger <cg@exept.de>
parents:
1312
diff
changeset
|
1373 |
"Modified: 6.5.1996 / 10:35:26 / cg" |
608 | 1374 |
! |
1375 |
||
1376 |
replChar:oldChar with:newChar |
|
1377 |
"return a copy of the receiver, with all oldChars replaced |
|
1378 |
by newChar. |
|
1379 |
This is an ST/V compatibility method." |
|
1380 |
||
1381 |
^ self copy replaceAll:oldChar by:newChar |
|
1382 |
||
1383 |
" |
|
1384 |
'12345678901234567890' replChar:$0 with:$* |
|
1385 |
" |
|
1386 |
! |
|
1387 |
||
1388 |
replChar:oldChar withString:newString |
|
1389 |
"return a copy of the receiver, with all oldChars replaced |
|
1390 |
by newString (i.e. slice in the newString in place of the oldChar). |
|
1391 |
This is an ST/V compatibility method." |
|
1392 |
||
1393 |
|tmpStream| |
|
1394 |
||
1395 |
tmpStream := WriteStream on:(self class new). |
|
1396 |
self do:[:element | |
|
1397 |
element = oldChar ifTrue:[ |
|
1398 |
tmpStream nextPutAll:newString |
|
1399 |
] ifFalse:[ |
|
1400 |
tmpStream nextPut:element |
|
1401 |
]. |
|
1402 |
]. |
|
1403 |
^ tmpStream contents |
|
1404 |
||
1405 |
" |
|
1406 |
'12345678901234567890' replChar:$0 withString:'foo' |
|
1407 |
'a string with spaces' replChar:$ withString:' foo ' |
|
1408 |
" |
|
1409 |
! |
|
1410 |
||
1411 |
trimBlanks |
|
1412 |
"return a copy of the receiver without leading |
|
1413 |
and trailing spaces. |
|
1414 |
This is an ST/V compatibility method." |
|
1415 |
||
1416 |
^ self withoutSpaces |
|
1417 |
||
1418 |
" |
|
1419 |
' spaces at beginning' trimBlanks |
|
1420 |
'spaces at end ' trimBlanks |
|
1421 |
' spaces at beginning and end ' trimBlanks |
|
1422 |
'no spaces' trimBlanks |
|
1423 |
" |
|
1424 |
! ! |
|
1425 |
||
1426 |
!CharacterArray methodsFor:'Compatibility - VisualAge'! |
|
1427 |
||
1428 |
addLineDelimiter |
|
1429 |
"replace all '\'-characters by line delimiter (cr) - characters. |
|
1430 |
This has been added for VisualAge compatibility." |
|
1431 |
||
1432 |
^ self withCRs |
|
1433 |
! |
|
1434 |
||
1435 |
bindWith:aString |
|
1436 |
"return a copy of the receiver, where a '%1' escape is |
|
1437 |
replaced by aString. |
|
1438 |
This has been added for VisualAge compatibility." |
|
1439 |
||
1440 |
^ self expandPlaceholdersWith:(Array with:aString) |
|
1441 |
||
1442 |
" |
|
1443 |
'do you like %1 ?' bindWith:'smalltalk' |
|
1444 |
" |
|
1445 |
! |
|
1446 |
||
1447 |
bindWith:string1 with:string2 |
|
1448 |
"return a copy of the receiver, where a '%1' escape is |
|
1449 |
replaced by string1 and '%2' is replaced by string2. |
|
1450 |
This has been added for VisualAge compatibility." |
|
1451 |
||
1452 |
^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
1453 |
||
1454 |
" |
|
1455 |
'do you prefer %1 or rather %2 ?' |
|
1456 |
bindWith:'smalltalk' with:'c++' |
|
1457 |
" |
|
1458 |
! |
|
1459 |
||
1460 |
bindWith:str1 with:str2 with:str3 |
|
1461 |
"return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
1462 |
are replaced by str1, str2 and str3 respectively. |
|
1463 |
This has been added for VisualAge compatibility." |
|
1464 |
||
1465 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
1466 |
||
1467 |
" |
|
1468 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
1469 |
bindWith:'smalltalk' with:'c++' with:'c' |
|
1470 |
" |
|
1471 |
! |
|
1472 |
||
1473 |
bindWith:str1 with:str2 with:str3 with:str4 |
|
1474 |
"return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
1475 |
are replaced by str1, str2, str3 and str4 respectively. |
|
1476 |
This has been added for VisualAge compatibility." |
|
1477 |
||
1478 |
^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
1479 |
||
1480 |
" |
|
1481 |
'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
1482 |
bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
1483 |
" |
|
1484 |
! |
|
1485 |
||
1486 |
bindWithArguments:anArrayOfStrings |
|
1487 |
"return a copy of the receiver, where a '%i' escape |
|
1488 |
is replaced by the coresponding string from the argument array. |
|
1489 |
'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
1490 |
This has been added for VisualAge compatibility." |
|
1491 |
||
1492 |
^ self expandPlaceholdersWith:anArrayOfStrings |
|
1493 |
||
1494 |
" |
|
1495 |
'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
1496 |
bindWithArguments:#('smalltalk' 'c++' 'c') |
|
1497 |
" |
|
1498 |
! |
|
1499 |
||
1500 |
subStrings |
|
1501 |
"return an array consisting of all words contained in the receiver. |
|
1502 |
Words are separated by whitespace. |
|
1503 |
This has been added for VisualAge compatibility." |
|
1504 |
||
1505 |
^ self asCollectionOfWords |
|
1506 |
||
1507 |
" |
|
1508 |
'hello world, this is smalltalk' subStrings |
|
1509 |
" |
|
1510 |
! |
|
1511 |
||
1512 |
subStrings:separatorCharacter |
|
1513 |
"return an array consisting of all words contained in the receiver. |
|
1514 |
Words are separated by separatorCharacter. |
|
1515 |
This has been added for VisualAge compatibility." |
|
1516 |
||
1517 |
^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
1518 |
||
1519 |
" |
|
1520 |
'foo:bar:baz:smalltalk' subStrings:$: |
|
1521 |
" |
|
1522 |
! |
|
1523 |
||
1524 |
trimSeparators |
|
1525 |
"return a copy of the receiver without leading and trailing whiteSpace" |
|
1526 |
||
1527 |
^ self withoutSeparators |
|
1528 |
! ! |
|
1529 |
||
1530 |
!CharacterArray methodsFor:'character searching'! |
|
1531 |
||
1532 |
includesMatchCharacters |
|
1533 |
"return true if the receiver includes any meta characters (i.e. $* or $#) |
|
1534 |
for match operations; false if not" |
|
1535 |
||
1536 |
^ self includesAny:'*#[' |
|
1537 |
! |
|
1538 |
||
1539 |
indexOfNonSeparatorStartingAt:startIndex |
|
1540 |
"return the index of the next non-whitespace character" |
|
1541 |
||
1542 |
|start "{ Class: SmallInteger }" |
|
1543 |
mySize "{ Class: SmallInteger }"| |
|
1544 |
||
1545 |
start := startIndex. |
|
1546 |
mySize := self size. |
|
1547 |
||
1548 |
start to:mySize do:[:index | |
|
1549 |
(self at:index) isSeparator ifFalse:[^ index] |
|
1550 |
]. |
|
1551 |
^ 0 |
|
1552 |
||
1553 |
" |
|
1554 |
' hello world' indexOfNonSeparatorStartingAt:1 |
|
1555 |
" |
|
1556 |
" |
|
1557 |
|s index1 index2| |
|
1558 |
s := ' foo bar baz'. |
|
1559 |
index1 := s indexOfNonSeparatorStartingAt:1. |
|
1560 |
index2 := s indexOfSeparatorStartingAt:index1. |
|
1561 |
s copyFrom:index1 to:index2 - 1 |
|
1562 |
" |
|
1563 |
! |
|
1564 |
||
1565 |
indexOfSeparator |
|
1566 |
"return the index of the first whitespace character" |
|
1567 |
||
1568 |
^ self indexOfSeparatorStartingAt:1 |
|
1569 |
||
1570 |
"'hello world' indexOfSeparator" |
|
1571 |
! |
|
1572 |
||
1573 |
indexOfSeparatorStartingAt:startIndex |
|
1574 |
"return the index of the next whitespace character" |
|
1575 |
||
1576 |
|start "{ Class: SmallInteger }" |
|
1577 |
mySize "{ Class: SmallInteger }"| |
|
1578 |
||
1579 |
start := startIndex. |
|
1580 |
mySize := self size. |
|
1581 |
||
1582 |
start to:mySize do:[:index | |
|
1583 |
(self at:index) isSeparator ifTrue:[^ index] |
|
1584 |
]. |
|
1585 |
^ 0 |
|
1586 |
||
1587 |
"'hello world' indexOfSeparatorStartingAt:3" |
|
1588 |
! ! |
|
1589 |
||
1590 |
!CharacterArray methodsFor:'comparing'! |
|
1591 |
||
1592 |
< something |
|
1593 |
"Compare the receiver with the argument and return true if the |
|
1252 | 1594 |
receiver is less than the argument. Otherwise return false. |
1595 |
This comparison is based on the elements ascii code - |
|
1596 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 1597 |
|
1598 |
^ (something > self) |
|
1252 | 1599 |
|
1600 |
"Modified: 22.4.1996 / 15:54:54 / cg" |
|
608 | 1601 |
! |
1602 |
||
1603 |
<= something |
|
1604 |
"Compare the receiver with the argument and return true if the |
|
1252 | 1605 |
receiver is less than or equal to the argument. Otherwise return false. |
1606 |
This comparison is based on the elements ascii code - |
|
1607 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 1608 |
|
1609 |
^ (self > something) not |
|
1252 | 1610 |
|
1611 |
"Modified: 22.4.1996 / 15:54:56 / cg" |
|
608 | 1612 |
! |
1613 |
||
1614 |
= aString |
|
1615 |
"Compare the receiver with the argument and return true if the |
|
1616 |
receiver is equal to the argument. Otherwise return false. |
|
1252 | 1617 |
|
608 | 1618 |
This compare does NOT ignore case differences, |
1619 |
therefore 'foo' = 'Foo' will return false. |
|
1620 |
Since this is incompatible to ST-80 (at least, V2.x) , this may change." |
|
1621 |
||
1622 |
|mySize "{ Class: SmallInteger }" |
|
1623 |
otherSize | |
|
1624 |
||
1625 |
aString species == self species ifFalse:[^ false]. |
|
1626 |
mySize := self size. |
|
1627 |
otherSize := aString size. |
|
1628 |
mySize == otherSize ifFalse:[^ false]. |
|
1629 |
||
1630 |
1 to:mySize do:[:index | |
|
1252 | 1631 |
(self at:index) = (aString at:index) ifFalse:[^ false]. |
608 | 1632 |
]. |
1633 |
^ true |
|
1634 |
||
1635 |
" |
|
1636 |
'foo' = 'Foo' |
|
1637 |
'foo' = 'bar' |
|
1638 |
'foo' = 'foo' |
|
1639 |
" |
|
1252 | 1640 |
|
1641 |
"Modified: 22.4.1996 / 15:53:58 / cg" |
|
608 | 1642 |
! |
1643 |
||
1644 |
> aString |
|
1645 |
"Compare the receiver with the argument and return true if the |
|
1646 |
receiver is greater than the argument. Otherwise return false. |
|
1252 | 1647 |
This comparison is based on the elements ascii code - |
1648 |
i.e. upper/lowercase & upper/lowercase & national characters are NOT treated specially." |
|
608 | 1649 |
|
1650 |
|mySize "{ Class: SmallInteger }" |
|
1651 |
otherSize "{ Class: SmallInteger }" |
|
1652 |
n "{ Class: SmallInteger }" |
|
1653 |
c1 c2| |
|
1654 |
||
1655 |
mySize := self size. |
|
1656 |
otherSize := aString size. |
|
1657 |
n := mySize min:otherSize. |
|
1658 |
||
1659 |
1 to:n do:[:index | |
|
1252 | 1660 |
c1 := self at:index. |
1661 |
c2 := aString at:index. |
|
1662 |
c1 > c2 ifTrue:[^ true]. |
|
1663 |
c1 < c2 ifTrue:[^ false]. |
|
608 | 1664 |
]. |
1665 |
^ mySize > otherSize |
|
1252 | 1666 |
|
1667 |
"Modified: 22.4.1996 / 15:55:00 / cg" |
|
608 | 1668 |
! |
1669 |
||
1670 |
>= something |
|
1671 |
"Compare the receiver with the argument and return true if the |
|
1672 |
receiver is greater than or equal to the argument. |
|
1252 | 1673 |
Otherwise return false. |
1674 |
This comparison is based on the elements ascii code - |
|
1675 |
i.e. upper/lowercase & national characters are NOT treated specially." |
|
608 | 1676 |
|
1677 |
^ (something > self) not |
|
1252 | 1678 |
|
1679 |
"Modified: 22.4.1996 / 15:55:03 / cg" |
|
608 | 1680 |
! |
1681 |
||
1682 |
compareWith:aString |
|
1683 |
"Compare the receiver with the argument and return 1 if the receiver is |
|
1684 |
greater, 0 if equal and -1 if less than the argument. |
|
1252 | 1685 |
This comparison is based on the elements ascii code - |
1686 |
i.e. upper/lowercase & national characters are NOT treated specially. |
|
1687 |
'foo' compareWith: 'Foo' will return 1. |
|
1688 |
while 'foo' sameAs:'Foo' will return true" |
|
608 | 1689 |
|
1690 |
|mySize "{ Class: SmallInteger }" |
|
1691 |
otherSize "{ Class: SmallInteger }" |
|
1692 |
n "{ Class: SmallInteger }" |
|
1693 |
c1 c2| |
|
1694 |
||
1695 |
mySize := self size. |
|
1696 |
otherSize := aString size. |
|
1697 |
n := mySize min:otherSize. |
|
1698 |
||
1699 |
1 to:n do:[:index | |
|
1252 | 1700 |
c1 := self at:index. |
1701 |
c2 := aString at:index. |
|
1702 |
c1 > c2 ifTrue:[^ 1]. |
|
1703 |
c1 < c2 ifTrue:[^ -1]. |
|
608 | 1704 |
]. |
1705 |
mySize > otherSize ifTrue:[^ 1]. |
|
1706 |
mySize < otherSize ifTrue:[^ -1]. |
|
1707 |
^ 0 |
|
1252 | 1708 |
|
1709 |
"Modified: 22.4.1996 / 15:56:07 / cg" |
|
608 | 1710 |
! |
1711 |
||
1712 |
hash |
|
1713 |
"return an integer useful as a hash-key" |
|
1714 |
||
1715 |
%{ /* NOCONTEXT */ |
|
1716 |
||
1717 |
REGISTER int g, val; |
|
1718 |
REGISTER unsigned char *cp, *cp0; |
|
1719 |
int l; |
|
1720 |
||
1133 | 1721 |
cp = __stringVal(self); |
1722 |
l = __stringSize(self); |
|
1723 |
if (__qClass(self) != @global(String)) { |
|
1724 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); |
|
608 | 1725 |
|
1726 |
cp += n; |
|
1727 |
l -= n; |
|
1728 |
} |
|
1729 |
||
1730 |
/* |
|
1731 |
* this is the dragon-book algorithm with a funny start |
|
1732 |
* value (to give short strings a number above 8192) |
|
1733 |
*/ |
|
1734 |
val = 12345; |
|
1735 |
for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { |
|
1736 |
val = (val << 5) + (*cp & 0x1F); |
|
1737 |
if (g = (val & 0x3E000000)) |
|
1738 |
val ^= g >> 25 /* 23 */ /* 25 */; |
|
1739 |
val &= 0x3FFFFFFF; |
|
1740 |
} |
|
1741 |
||
1742 |
if (l) { |
|
1743 |
l |= 1; |
|
1744 |
val = (val * l) & 0x3FFFFFFF; |
|
1745 |
} |
|
1746 |
||
1133 | 1747 |
RETURN ( __MKSMALLINT(val) ); |
608 | 1748 |
%} |
1749 |
! |
|
1750 |
||
1751 |
sameAs:aString |
|
1752 |
"Compare the receiver with the argument like =, but ignore |
|
1252 | 1753 |
case differences. |
1754 |
Return true or false." |
|
608 | 1755 |
|
1756 |
|mySize "{ Class: SmallInteger }" |
|
1757 |
otherSize c1 c2| |
|
1758 |
||
1759 |
mySize := self size. |
|
1760 |
otherSize := aString size. |
|
1761 |
mySize == otherSize ifFalse:[^ false]. |
|
1762 |
||
1763 |
1 to:mySize do:[:index | |
|
1252 | 1764 |
c1 := self at:index. |
1765 |
c2 := aString at:index. |
|
1766 |
c1 == c2 ifFalse:[ |
|
1767 |
c1 asLowercase = c2 asLowercase ifFalse:[^ false]. |
|
1768 |
] |
|
608 | 1769 |
]. |
1770 |
^ true |
|
1771 |
||
1772 |
" |
|
1773 |
'foo' sameAs: 'Foo' |
|
1774 |
'foo' sameAs: 'bar' |
|
1775 |
'foo' sameAs: 'foo' |
|
1776 |
" |
|
1252 | 1777 |
|
1778 |
"Modified: 22.4.1996 / 15:56:17 / cg" |
|
608 | 1779 |
! |
1780 |
||
1781 |
sameCharacters:aString |
|
1782 |
"count & return the number of characters which are the same |
|
1783 |
(ignoring case) in the receiver and the argument, aString." |
|
1784 |
||
1785 |
|n "{ Class: SmallInteger }" |
|
986 | 1786 |
c1 c2 cnt| |
608 | 1787 |
|
1788 |
n := self size. |
|
1789 |
n := n min:(aString size). |
|
1790 |
||
1791 |
cnt := 0. |
|
1792 |
1 to:n do:[:index | |
|
1793 |
c1 := self at:index. |
|
1794 |
c2 := aString at:index. |
|
1795 |
((c1 == c2) |
|
1796 |
or:[c1 asLowercase = c2 asLowercase]) ifTrue:[ |
|
1797 |
cnt := cnt + 1 |
|
1798 |
] |
|
1799 |
]. |
|
1800 |
^ cnt |
|
1801 |
||
1802 |
" |
|
1803 |
'foobarbaz' sameCharacters: 'foo' |
|
1804 |
'foobarbaz' sameCharacters: 'Foo' |
|
1805 |
'foobarbaz' sameCharacters: 'baz' |
|
1806 |
" |
|
1807 |
! ! |
|
1808 |
||
1809 |
!CharacterArray methodsFor:'converting'! |
|
1810 |
||
1811 |
asArrayOfSubstrings |
|
1812 |
"return an array of substrings from the receiver, interpreting |
|
1813 |
separators (i.e. spaces & newlines) as word-delimiters. |
|
1814 |
This is a compatibility method - the actual work is done in |
|
1815 |
asCollectionOfWords." |
|
1816 |
||
1817 |
^ self asCollectionOfWords asArray |
|
1818 |
||
1819 |
" |
|
1820 |
'1 one two three four 5 five' asArrayOfSubstrings |
|
1821 |
" |
|
1822 |
! |
|
1823 |
||
1824 |
asCollectionOfLines |
|
1825 |
"return a collection containing the lines (separated by cr) |
|
1826 |
of the receiver. If multiple cr's occur in a row, the result will |
|
1827 |
contain empty strings." |
|
1828 |
||
1829 |
^ self asCollectionOfSubstringsSeparatedBy:Character cr |
|
1830 |
||
1831 |
" |
|
1832 |
'1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines |
|
1833 |
'1 one\\\\2 two\3 three' withCRs asCollectionOfLines |
|
1834 |
" |
|
1835 |
! |
|
1836 |
||
1837 |
asCollectionOfSubstringsSeparatedBy:aCharacter |
|
1838 |
"return a collection containing the lines (separated by aCharacter) |
|
1839 |
of the receiver. If aCharacter occurs multiple times in a row, |
|
1840 |
the result will contain empty strings." |
|
1841 |
||
1842 |
|lines myClass |
|
1843 |
numberOfLines "{ Class:SmallInteger }" |
|
1844 |
startIndex "{ Class:SmallInteger }" |
|
1845 |
stopIndex "{ Class:SmallInteger }" | |
|
1846 |
||
1847 |
" |
|
1848 |
count first, to avoid regrowing of the OC |
|
1849 |
" |
|
1850 |
numberOfLines := (self occurrencesOf:aCharacter) + 1. |
|
1851 |
lines := OrderedCollection new:numberOfLines. |
|
1852 |
myClass := self species. |
|
1853 |
||
1854 |
startIndex := 1. |
|
1855 |
1 to:numberOfLines do:[:lineNr | |
|
1856 |
stopIndex := self indexOf:aCharacter startingAt:startIndex. |
|
1857 |
stopIndex == 0 ifTrue:[ |
|
1858 |
stopIndex := self size |
|
1859 |
] ifFalse: [ |
|
1860 |
stopIndex := stopIndex - 1. |
|
1861 |
]. |
|
1862 |
||
1863 |
(stopIndex < startIndex) ifTrue: [ |
|
1864 |
lines add:(myClass new:0) |
|
1865 |
] ifFalse: [ |
|
1866 |
lines add:(self copyFrom:startIndex to:stopIndex) |
|
1867 |
]. |
|
1868 |
startIndex := stopIndex + 2 |
|
1869 |
]. |
|
1870 |
^ lines |
|
1871 |
||
1872 |
" |
|
1873 |
'1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: |
|
1874 |
'1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space |
|
1875 |
" |
|
1876 |
! |
|
1877 |
||
1878 |
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators |
|
1879 |
"return a collection containing the words (separated by any character |
|
1880 |
from aCollectionOfSeparators) of the receiver. |
|
1881 |
This allows breaking up strings using any character as separator." |
|
1882 |
||
1883 |
|words |
|
1884 |
start "{ Class:SmallInteger }" |
|
1885 |
stop "{ Class:SmallInteger }" |
|
1886 |
mySize "{ Class:SmallInteger }"| |
|
1887 |
||
1888 |
words := OrderedCollection new. |
|
1889 |
start := 1. |
|
1890 |
mySize := self size. |
|
1891 |
[start <= mySize] whileTrue:[ |
|
1892 |
"skip multiple separators" |
|
1893 |
[aCollectionOfSeparators includes:(self at:start)] whileTrue:[ |
|
1894 |
start := start + 1 . |
|
1895 |
start > mySize ifTrue:[ |
|
1896 |
^ words |
|
1897 |
]. |
|
1898 |
]. |
|
1899 |
||
1900 |
stop := self indexOfAny:aCollectionOfSeparators startingAt:start. |
|
1901 |
stop == 0 ifTrue:[ |
|
1902 |
words add:(self copyFrom:start to:mySize). |
|
1903 |
^ words |
|
1904 |
]. |
|
1905 |
words add:(self copyFrom:start to:(stop - 1)). |
|
1906 |
start := stop |
|
1907 |
]. |
|
1908 |
^ words |
|
1909 |
||
1910 |
" |
|
1911 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:) |
|
1912 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' |
|
1913 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) |
|
1914 |
'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' |
|
1915 |
'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) |
|
1916 |
" |
|
1917 |
! |
|
1918 |
||
1919 |
asCollectionOfWords |
|
1920 |
"return a collection containing the words (separated by whitespace) |
|
1921 |
of the receiver. Multiple occurences of whitespace characters will |
|
1922 |
be treated like one - i.e. whitespace is skipped." |
|
1923 |
||
1924 |
|words |
|
1925 |
start "{ Class:SmallInteger }" |
|
1926 |
stop "{ Class:SmallInteger }" |
|
1927 |
mySize "{ Class:SmallInteger }"| |
|
1928 |
||
1929 |
words := OrderedCollection new. |
|
1930 |
start := 1. |
|
1931 |
mySize := self size. |
|
1932 |
[start <= mySize] whileTrue:[ |
|
1933 |
start := self indexOfNonSeparatorStartingAt:start. |
|
1934 |
start == 0 ifTrue:[ |
|
1935 |
^ words |
|
1936 |
]. |
|
1937 |
stop := self indexOfSeparatorStartingAt:start. |
|
1938 |
stop == 0 ifTrue:[ |
|
1939 |
words add:(self copyFrom:start to:mySize). |
|
1940 |
^ words |
|
1941 |
]. |
|
1942 |
words add:(self copyFrom:start to:(stop - 1)). |
|
1943 |
start := stop |
|
1944 |
]. |
|
1945 |
^ words |
|
1946 |
||
1947 |
" |
|
1948 |
'hello world isnt this nice' asCollectionOfWords |
|
1949 |
' hello world isnt this nice ' asCollectionOfWords |
|
1950 |
'hello' asCollectionOfWords |
|
1951 |
'' asCollectionOfWords |
|
1952 |
' ' asCollectionOfWords |
|
1953 |
" |
|
1954 |
! |
|
1955 |
||
1956 |
asComposedText |
|
1312 | 1957 |
"ST-80 compatibility |
1958 |
- ST/X does not (as today) support composedTexts." |
|
1959 |
||
608 | 1960 |
^ ComposedText fromString:self |
1312 | 1961 |
|
1962 |
"Modified: 27.4.1996 / 13:30:30 / cg" |
|
608 | 1963 |
! |
1964 |
||
1965 |
asFilename |
|
1966 |
"return a Filename with pathname taken from the receiver" |
|
1967 |
||
1968 |
^ Filename named:self |
|
1969 |
! |
|
1970 |
||
1971 |
asFloat |
|
1972 |
"read a float number from the receiver. |
|
1973 |
Notice, that errors may occur during the read, so you better |
|
1974 |
setup some signal handler when using this method." |
|
1975 |
||
1976 |
^ (Number readFromString:self) asFloat |
|
1977 |
||
1978 |
" |
|
1979 |
'0.123' asFloat |
|
1980 |
'12345' asFloat |
|
1981 |
'(1/5)' asFloat |
|
1982 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] |
|
1983 |
" |
|
1984 |
! |
|
1985 |
||
1986 |
asInteger |
|
1987 |
"read an integer from the receiver. |
|
1988 |
Notice, that errors may occur during the read, so you better |
|
1989 |
setup some signal handler when using this method." |
|
1990 |
||
1991 |
^ Integer readFromString:self |
|
1992 |
||
1993 |
" |
|
1994 |
'12345678901234567890' asInteger |
|
1995 |
'-1234' asInteger |
|
1996 |
'0.123' asInteger <- reader stops at ., returning 0 here |
|
1997 |
'0.123' asNumber <- returns what you expect |
|
1998 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] |
|
1999 |
" |
|
2000 |
! |
|
2001 |
||
2002 |
asLowercase |
|
2003 |
"return a copy of myself in lowercase letters" |
|
2004 |
||
2005 |
|newStr |
|
2006 |
mySize "{ Class: SmallInteger }" | |
|
2007 |
||
2008 |
mySize := self size. |
|
2009 |
newStr := self species new:mySize. |
|
2010 |
1 to:mySize do:[:i | |
|
2011 |
newStr at:i put:(self at:i) asLowercase |
|
2012 |
]. |
|
2013 |
^ newStr |
|
2014 |
||
2015 |
" |
|
2016 |
'HelloWorld' asLowercase |
|
2017 |
'HelloWorld' asLowercaseFirst |
|
2018 |
" |
|
2019 |
! |
|
2020 |
||
2021 |
asLowercaseFirst |
|
2022 |
"return a copy of myself where the first character is |
|
2023 |
converted to lowercase." |
|
2024 |
||
2025 |
|newString sz| |
|
2026 |
||
2027 |
sz := self size. |
|
2028 |
newString := self copyFrom:1 to:sz. |
|
2029 |
sz > 0 ifTrue:[ |
|
2030 |
newString at:1 put:(newString at:1) asLowercase |
|
2031 |
]. |
|
2032 |
^ newString |
|
2033 |
||
2034 |
" |
|
2035 |
'HelloWorld' asLowercase |
|
2036 |
'HelloWorld' asLowercaseFirst |
|
2037 |
" |
|
2038 |
! |
|
2039 |
||
2040 |
asNumber |
|
2041 |
"read a number from the receiver. |
|
2042 |
Notice, that (in contrast to ST-80) errors may occur during the read, |
|
2043 |
so you better setup some signal handler when using this method. |
|
2044 |
This may change if ANSI specifies it." |
|
2045 |
||
2046 |
"/ ST-80 behavior: |
|
2047 |
"/ ^ Number readFromString:self onError:0 |
|
2048 |
||
2049 |
^ Number readFromString:self |
|
2050 |
||
2051 |
" |
|
2052 |
'123' asNumber |
|
2053 |
'123.567' asNumber |
|
2054 |
'(5/6)' asNumber |
|
2055 |
'foo' asNumber |
|
2056 |
Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] |
|
2057 |
" |
|
2058 |
! |
|
2059 |
||
2060 |
asNumberFromFormatString:ignored |
|
2061 |
"read a number from the receiver, ignoring any nonDigit characters. |
|
2062 |
This is typically used to convert from strings which include |
|
2063 |
dollar-signs or millenium digits. However, this method also ignores |
|
2064 |
the decimal point (if any) and therefore should be used with care." |
|
2065 |
||
2066 |
|tempString| |
|
2067 |
||
2068 |
tempString := self collect:[:char | char isDigit]. |
|
2069 |
^ Number readFromString:tempString onError:0 |
|
2070 |
||
2071 |
" |
|
2072 |
'USD 123' asNumberFromFormatString:'foo' |
|
2073 |
'DM 123' asNumberFromFormatString:'foo' |
|
2074 |
'123' asNumberFromFormatString:'foo' |
|
2075 |
'123.567' asNumberFromFormatString:'foo' |
|
2076 |
'(5/6)' asNumberFromFormatString:'foo' |
|
2077 |
'foo' asNumberFromFormatString:'foo' |
|
2078 |
" |
|
2079 |
! |
|
2080 |
||
2081 |
asSingleByteString |
|
2082 |
"return the receiver converted to a 'normal' string" |
|
2083 |
||
2084 |
^ String fromString:self |
|
2085 |
! |
|
2086 |
||
2087 |
asString |
|
2088 |
"return myself - I am a string" |
|
2089 |
||
2090 |
^ self |
|
2091 |
! |
|
2092 |
||
2093 |
asStringCollection |
|
2094 |
"return a collection of lines from myself." |
|
2095 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2096 |
^ StringCollection from:self string |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2097 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2098 |
"Modified: 11.5.1996 / 14:09:53 / cg" |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2099 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2100 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2101 |
asText |
1381 | 2102 |
"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
|
2103 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2104 |
^ Text fromString:self |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2105 |
|
1381 | 2106 |
"Created: 12.5.1996 / 10:41:14 / cg" |
608 | 2107 |
! |
2108 |
||
2109 |
asTwoByteString |
|
2110 |
"return the receiver converted to a two-byte string" |
|
2111 |
||
2112 |
^ TwoByteString fromString:self |
|
2113 |
! |
|
2114 |
||
2115 |
asUppercase |
|
2116 |
"return a copy of myself in uppercase letters" |
|
2117 |
||
2118 |
|newStr |
|
2119 |
mySize "{ Class: SmallInteger }" | |
|
2120 |
||
2121 |
mySize := self size. |
|
2122 |
newStr := self species new:mySize. |
|
2123 |
1 to:mySize do:[:i | |
|
2124 |
newStr at:i put:(self at:i) asUppercase |
|
2125 |
]. |
|
2126 |
^ newStr |
|
2127 |
||
2128 |
" |
|
2129 |
'helloWorld' asUppercase |
|
2130 |
'helloWorld' asUppercaseFirst |
|
2131 |
" |
|
2132 |
! |
|
2133 |
||
2134 |
asUppercaseFirst |
|
2135 |
"return a copy of myself where the first character is |
|
2136 |
converted to uppercase." |
|
2137 |
||
2138 |
|newString sz| |
|
2139 |
||
2140 |
sz := self size. |
|
2141 |
newString := self copyFrom:1 to:sz. |
|
2142 |
sz > 0 ifTrue:[ |
|
2143 |
newString at:1 put:(newString at:1) asUppercase |
|
2144 |
]. |
|
2145 |
^ newString |
|
2146 |
||
2147 |
" |
|
2148 |
'helloWorld' asUppercase |
|
2149 |
'helloWorld' asUppercaseFirst |
|
2150 |
'HelloWorld' asUppercaseFirst |
|
2151 |
" |
|
2152 |
! |
|
2153 |
||
2154 |
string |
|
1312 | 2155 |
"return the receiver - for ST-80 compatibility" |
2156 |
||
608 | 2157 |
^ self |
1312 | 2158 |
|
2159 |
"Modified: 27.4.1996 / 13:29:30 / cg" |
|
608 | 2160 |
! |
2161 |
||
2162 |
tokensBasedOn:aCharacter |
|
2163 |
"this is an ST-80 alias for the ST/X method |
|
2164 |
asCollectionOfSubstringsSeparatedBy:" |
|
2165 |
||
2166 |
^ self asCollectionOfSubstringsSeparatedBy:aCharacter |
|
2167 |
||
2168 |
" |
|
2169 |
'hello:world:isnt:this nice' tokensBasedOn:$: |
|
2170 |
'foo,bar,baz' tokensBasedOn:$, |
|
2171 |
'/etc/passwd' asFilename readStream nextLine tokensBasedOn:$: |
|
2172 |
" |
|
2173 |
! ! |
|
2174 |
||
2175 |
!CharacterArray methodsFor:'copying'! |
|
2176 |
||
1050
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2177 |
, aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2178 |
"redefined to allow characters to be appended. |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2179 |
This is nonStandard, but convenient" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2180 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2181 |
aStringOrCharacter isCharacter ifTrue:[ |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2182 |
^ self , aStringOrCharacter asString |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2183 |
]. |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2184 |
^ super , aStringOrCharacter |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2185 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2186 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2187 |
'hello' , $1 |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2188 |
'hello' , '1' |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2189 |
" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2190 |
|
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2191 |
"Modified: 29.2.1996 / 20:37:36 / cg" |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2192 |
! |
2f14bbd792a9
, now accepts a character-argument
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
2193 |
|
608 | 2194 |
concatenate:string1 and:string2 |
2195 |
"return the concatenation of myself and the arguments, string1 and string2. |
|
2196 |
This is equivalent to self , string1 , string2 |
|
2197 |
- generated by compiler when such a construct is detected and the receiver |
|
2198 |
is known to be a string." |
|
2199 |
||
2200 |
^ self , string1 , string2 |
|
2201 |
! |
|
2202 |
||
2203 |
concatenate:string1 and:string2 and:string3 |
|
2204 |
"return the concatenation of myself and the string arguments. |
|
2205 |
This is equivalent to self , string1 , string2 , string3 |
|
2206 |
- generated by compiler when such a construct is detected and the receiver |
|
2207 |
is known to be a string." |
|
2208 |
||
2209 |
^ self , string1 , string2 , string3 |
|
2210 |
! ! |
|
2211 |
||
2212 |
!CharacterArray methodsFor:'displaying'! |
|
2213 |
||
2214 |
displayOn:aGc x:x y:y |
|
2215 |
"display the receiver in a graphicsContext - this method allows |
|
2216 |
strings to be used like DisplayObjects." |
|
2217 |
||
1381 | 2218 |
^ aGc displayString:self string x:x y:y. |
2219 |
||
2220 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
2221 |
! |
|
2222 |
||
2223 |
displayOpaqueOn:aGc x:x y:y |
|
2224 |
"display the receiver in a graphicsContext - this method allows |
|
2225 |
strings to be used like DisplayObjects." |
|
2226 |
||
2227 |
^ aGc displayOpaqueString:self string x:x y:y. |
|
2228 |
||
2229 |
"Modified: 11.5.1996 / 14:42:48 / cg" |
|
2230 |
"Created: 12.5.1996 / 12:28:40 / cg" |
|
608 | 2231 |
! ! |
2232 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2233 |
!CharacterArray methodsFor:'emphasis'! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2234 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2235 |
emphasisAt:characterIndex |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2236 |
"return the emphasis at some index. |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2237 |
Since characterArrays do not hold any emphasis information, |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2238 |
nil (no emphasis) is returned here." |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2239 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2240 |
^ nil |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2241 |
|
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2242 |
"Created: 11.5.1996 / 14:13:27 / cg" |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2243 |
! ! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2244 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2245 |
!CharacterArray methodsFor:'encoding/decoding'! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2246 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2247 |
decodeFrom:encodingSymbol |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2248 |
"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
|
2249 |
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
|
2250 |
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
|
2251 |
(and those are untested/incomplete): |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2252 |
#euc |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
2253 |
#jis7 |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2254 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2255 |
#msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2256 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2257 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2258 |
|newString| |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2259 |
|
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
2260 |
encodingSymbol == #jis7 ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2261 |
^ self class decodeFromJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2262 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2263 |
encodingSymbol == #euc ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2264 |
^ self class decodeFromEUC:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2265 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2266 |
encodingSymbol == #big5 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2267 |
^ self class 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
|
2268 |
]. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2269 |
encodingSymbol == #gb ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2270 |
^ self class decodeFromGB:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2271 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2272 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2273 |
newString := self class new:self size. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2274 |
newString replaceFrom:self decode:encodingSymbol. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2275 |
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
|
2276 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2277 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2278 |
"Created: 22.2.1996 / 15:06:49 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2279 |
"Modified: 17.4.1996 / 18:25:17 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2280 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2281 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2282 |
encodeInto:encodingSymbol |
997
6c7f1815ed02
more encoding & decoding support
Claus Gittinger <cg@exept.de>
parents:
991
diff
changeset
|
2283 |
"given the receiver in internal ST/X (ISO8859) encoding, |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2284 |
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
|
2285 |
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
|
2286 |
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
|
2287 |
(and those are untested/incomplete): |
1006 | 2288 |
#euc |
2289 |
#jis7 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2290 |
#mac |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2291 |
#msdos |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2292 |
" |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2293 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2294 |
|newString| |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2295 |
|
1204 | 2296 |
"/ 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
|
2297 |
|
1028 | 2298 |
encodingSymbol isNil ifTrue:[^ self]. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2299 |
encodingSymbol == self encoding ifTrue:[^ self]. |
1028 | 2300 |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2301 |
encodingSymbol == #jis7 ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2302 |
^ self class encodeIntoJIS7:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2303 |
]. |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
2304 |
(encodingSymbol startsWith:'jis') ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2305 |
^ self class encodeIntoJISwithRomans:self |
1013
0e54ddc990cb
more 16bit & encoding support
Claus Gittinger <cg@exept.de>
parents:
1012
diff
changeset
|
2306 |
]. |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2307 |
encodingSymbol == #euc ifTrue:[ |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2308 |
^ self class encodeIntoEUC:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2309 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2310 |
encodingSymbol == #big5 ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2311 |
^ self class encodeIntoBIG5:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2312 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2313 |
(encodingSymbol startsWith:'big5') ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2314 |
^ self class encodeIntoBIG5withRomans:self |
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
2315 |
]. |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2316 |
encodingSymbol == #gb ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2317 |
^ self class encodeIntoGB:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2318 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2319 |
(encodingSymbol startsWith:'gb') ifTrue:[ |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2320 |
^ self class encodeIntoGBwithRomans:self |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2321 |
]. |
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2322 |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2323 |
newString := self class new:self size. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2324 |
newString replaceFrom:self encode:encodingSymbol. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2325 |
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
|
2326 |
^ newString |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2327 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2328 |
"Created: 22.2.1996 / 15:07:31 / cg" |
1204 | 2329 |
"Modified: 17.4.1996 / 18:59:12 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2330 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2331 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2332 |
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
|
2333 |
"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
|
2334 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2335 |
^ 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
|
2336 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2337 |
"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
|
2338 |
"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
|
2339 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2340 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2341 |
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
|
2342 |
"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
|
2343 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2344 |
^ 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
|
2345 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2346 |
"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
|
2347 |
"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
|
2348 |
! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2349 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2350 |
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
|
2351 |
"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
|
2352 |
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
|
2353 |
|
1023 | 2354 |
|sz| |
2355 |
||
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2356 |
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
|
2357 |
encodingTable isNil ifTrue:[^ self]. |
1023 | 2358 |
sz := encodingTable size. |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2359 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2360 |
1 to:self size do:[:index | |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2361 |
|char oldCode newCode| |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2362 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2363 |
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
|
2364 |
oldCode := char asciiValue. |
1023 | 2365 |
oldCode >= sz ifFalse:[ |
2366 |
newCode := encodingTable at:(oldCode + 1). |
|
2367 |
newCode ~~ oldCode ifTrue:[ |
|
2368 |
self at:index put:(Character value:newCode) |
|
2369 |
] |
|
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2370 |
] |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2371 |
]. |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2372 |
|
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2373 |
"Created: 22.2.1996 / 16:07:26 / cg" |
1202
200f7cd0a457
moved encode/decode stuff into class methods / added big5/gb support
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2374 |
"Modified: 17.4.1996 / 16:06:30 / cg" |
991
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2375 |
! ! |
f0b45a4b82d2
first attempt in encoding/decoding for different character representations (mac/msdos etc.)
Claus Gittinger <cg@exept.de>
parents:
986
diff
changeset
|
2376 |
|
608 | 2377 |
!CharacterArray methodsFor:'padded copying'! |
2378 |
||
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2379 |
centerPaddedTo:newSize |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2380 |
"return a new string consisting of the receivers characters, |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2381 |
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
|
2382 |
the resulting string. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2383 |
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
|
2384 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2385 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2386 |
^ self centerPaddedTo:newSize with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2387 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2388 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2389 |
'foo' centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2390 |
123 printString centerPaddedTo:10 |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2391 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2392 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2393 |
"Created: 25.11.1995 / 10:53:57 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2394 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2395 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2396 |
centerPaddedTo:size with:padCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2397 |
"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
|
2398 |
centered (i.e. padded on both sides). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2399 |
Characters are filled with padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2400 |
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
|
2401 |
the original receiver is returned unchanged." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2402 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2403 |
|len s| |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2404 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2405 |
len := self size. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2406 |
(len < size) ifTrue:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2407 |
s := self species new:size withAll:padCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2408 |
s replaceFrom:(size - len) // 2 + 1 with:self. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2409 |
^ s |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2410 |
] |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2411 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2412 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2413 |
'foo' centerPaddedTo:11 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2414 |
'fooBar' centerPaddedTo:5 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2415 |
123 printString centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2416 |
(' ' , 123 printString) centerPaddedTo:10 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2417 |
(Float pi printString) centerPaddedTo:15 with:(Character space) |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2418 |
(Float pi printString) centerPaddedTo:15 with:$- |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2419 |
(' ' , Float pi class name) centerPaddedTo:15 with:$. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2420 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2421 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2422 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2423 |
decimalPaddedTo:size and:afterPeriod at:decimalCharacter |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2424 |
"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
|
2425 |
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
|
2426 |
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
|
2427 |
to be padded). |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2428 |
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
|
2429 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2430 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2431 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2432 |
^ self |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2433 |
decimalPaddedTo:size |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2434 |
and:afterPeriod |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2435 |
at:decimalCharacter |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2436 |
withLeft:(Character space) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2437 |
right:$0 |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2438 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2439 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2440 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2441 |
'123' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2442 |
'123.' decimalPaddedTo:10 and:3 at:$. -> ' 123.000' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2443 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.100' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2444 |
'123.1' decimalPaddedTo:10 and:3 at:$. -> ' 123.1 ' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2445 |
'123.123' decimalPaddedTo:10 and:3 at:$. -> ' 123.123' |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2446 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2447 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2448 |
"Created: 23.12.1995 / 13:11:52 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2449 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2450 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2451 |
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
|
2452 |
"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
|
2453 |
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
|
2454 |
of the period. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2455 |
Characters on the left are filled with leftPadChar. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2456 |
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
|
2457 |
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
|
2458 |
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
|
2459 |
the original receiver is returned unchanged. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2460 |
(sounds complicated ? -> see examples below)." |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2461 |
|
986 | 2462 |
|s idx n| |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2463 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2464 |
idx := self indexOf:decimalCharacter. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2465 |
idx == 0 ifTrue:[ |
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2466 |
"/ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2467 |
"/ no decimal point found; adjust string to the left of the period column |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2468 |
"/ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2469 |
rightPadChar isNil ifTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2470 |
s := self , (self species new:afterPeriod + 1 withAll:leftPadChar) |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2471 |
] ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2472 |
s:= self , decimalCharacter asString , (self species new:afterPeriod withAll:rightPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2473 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2474 |
] ifFalse:[ |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2475 |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2476 |
"/ the number of after-decimalPoint characters |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2477 |
n := self size - idx. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2478 |
rightPadChar isNil ifTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2479 |
s := self , (self species new:afterPeriod - n withAll:leftPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2480 |
] ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2481 |
s := self , (self species new:afterPeriod - n withAll:rightPadChar). |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
2482 |
]. |
815
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2483 |
]. |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2484 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2485 |
^ s leftPaddedTo:size with:leftPadChar |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2486 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2487 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2488 |
'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
|
2489 |
'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
|
2490 |
'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
|
2491 |
'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
|
2492 |
'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
|
2493 |
'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
|
2494 |
" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2495 |
|
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2496 |
"Modified: 23.12.1995 / 13:08:18 / cg" |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2497 |
! |
997a02c135e7
support for decimal padding added
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2498 |
|
608 | 2499 |
leftPaddedTo:size |
2500 |
"return a new string of length size, which contains the receiver |
|
2501 |
right-adjusted (i.e. padded on the left). |
|
2502 |
Characters on the left are filled with spaces. |
|
2503 |
If the receivers size is equal or greater than the length argument, |
|
2504 |
the original receiver is returned unchanged." |
|
2505 |
||
2506 |
^ self leftPaddedTo:size with:(Character space) |
|
2507 |
||
2508 |
" |
|
2509 |
'foo' leftPaddedTo:10 |
|
2510 |
'fooBar' leftPaddedTo:5 |
|
2511 |
123 printString leftPaddedTo:10 |
|
2512 |
" |
|
2513 |
! |
|
2514 |
||
2515 |
leftPaddedTo:size with:padCharacter |
|
2516 |
"return a new string of length size, which contains the receiver |
|
2517 |
right-adjusted (i.e. padded on the left). |
|
2518 |
Characters on the left are filled with padCharacter. |
|
2519 |
If the receivers size is equal or greater than the length argument, |
|
2520 |
the original receiver is returned unchanged." |
|
2521 |
||
2522 |
|len s| |
|
2523 |
||
2524 |
len := self size. |
|
2525 |
(len < size) ifTrue:[ |
|
2526 |
s := self species new:size withAll:padCharacter. |
|
2527 |
s replaceFrom:(size - len + 1) with:self. |
|
2528 |
^ s |
|
2529 |
] |
|
2530 |
||
2531 |
" |
|
2532 |
'foo' leftPaddedTo:10 with:$. |
|
2533 |
'fooBar' leftPaddedTo:5 with:$. |
|
2534 |
123 printString leftPaddedTo:10 with:$. |
|
2535 |
(' ' , 123 printString) leftPaddedTo:10 with:$. |
|
2536 |
(Float pi printString) leftPaddedTo:15 with:(Character space) |
|
2537 |
(Float pi printString) leftPaddedTo:15 with:$- |
|
2538 |
(' ' , Float pi class name) leftPaddedTo:15 with:$. |
|
2539 |
" |
|
2540 |
! |
|
2541 |
||
2542 |
paddedTo:newSize |
|
2543 |
"return a new string consisting of the receivers characters, |
|
2544 |
plus spaces up to length. |
|
2545 |
If the receivers size is equal or greater than the length argument, |
|
2546 |
the original receiver is returned unchanged." |
|
2547 |
||
2548 |
^ self paddedTo:newSize with:(Character space) |
|
2549 |
||
2550 |
" |
|
2551 |
'foo' paddedTo:10 |
|
2552 |
123 printString paddedTo:10 |
|
2553 |
" |
|
2554 |
! |
|
2555 |
||
2556 |
paddedTo:newSize with:padCharacter |
|
2557 |
"return a new string consisting of the receivers characters, |
|
2558 |
plus pad characters up to length. |
|
2559 |
If the receivers size is equal or greater than the length argument, |
|
2560 |
the original receiver is returned unchanged." |
|
2561 |
||
2562 |
|s len| |
|
2563 |
||
2564 |
len := self size. |
|
2565 |
len < newSize ifTrue:[ |
|
2566 |
s := self species new:newSize withAll:padCharacter. |
|
2567 |
s replaceFrom:1 to:len with:self. |
|
2568 |
^ s |
|
2569 |
] |
|
2570 |
||
2571 |
" |
|
2572 |
'foo' paddedTo:10 with:$. |
|
2573 |
123 printString paddedTo:10 with:$* |
|
2574 |
(Float pi printString) paddedTo:15 with:(Character space) |
|
2575 |
(Float pi printString) paddedTo:15 with:$- |
|
2576 |
(Float pi class name , ' ') paddedTo:15 with:$. |
|
2577 |
" |
|
64 | 2578 |
! ! |
2579 |
||
328 | 2580 |
!CharacterArray methodsFor:'pattern matching'! |
2581 |
||
2582 |
findMatchString:matchString |
|
368 | 2583 |
"like findString/indexOfSubCollection, but allowing match patterns. |
328 | 2584 |
find matchstring; if found, return the index; |
2585 |
if not found, return 0." |
|
2586 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2587 |
^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:0 |
328 | 2588 |
! |
2589 |
||
2590 |
findMatchString:matchString startingAt:index |
|
2591 |
"like findString, but allowing match patterns. |
|
2592 |
find matchstring, starting at index. if found, return the index; |
|
2593 |
if not found, return 0." |
|
2594 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2595 |
^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:0 |
328 | 2596 |
! |
2597 |
||
2598 |
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock |
|
2599 |
"like findString, but allowing match patterns. |
|
2600 |
find matchstring, starting at index. if found, return the index; |
|
2601 |
if not found, return the result of evaluating exceptionBlock. |
|
2602 |
This is a q&d hack - not very efficient" |
|
2603 |
||
2604 |
|firstChar |
|
2605 |
startIndex "{ Class: SmallInteger }" |
|
2606 |
matchSize "{ Class: SmallInteger }" |
|
2607 |
mySize "{ Class: SmallInteger }" |
|
2608 |
realMatchString| |
|
2609 |
||
2610 |
matchSize := matchString size. |
|
2611 |
matchSize == 0 ifTrue:[^ index]. "empty string matches" |
|
2612 |
||
2613 |
realMatchString := matchString. |
|
2614 |
(realMatchString endsWith:$*) ifFalse:[ |
|
2615 |
realMatchString := realMatchString , '*'. |
|
2616 |
matchSize := matchSize + 1 |
|
2617 |
]. |
|
2618 |
||
2619 |
mySize := self size. |
|
2620 |
firstChar := realMatchString at:1. |
|
2621 |
||
2622 |
firstChar asString includesMatchCharacters ifTrue:[ |
|
2623 |
index to:mySize do:[:col | |
|
2624 |
(realMatchString match:self from:col to:mySize ignoreCase:ignoreCase) |
|
2625 |
ifTrue:[^ col] |
|
2626 |
]. |
|
2627 |
^ exceptionBlock value. |
|
2628 |
]. |
|
2629 |
startIndex := self indexOf:firstChar startingAt:index. |
|
2630 |
[startIndex == 0] whileFalse:[ |
|
2631 |
(realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase) |
|
2632 |
ifTrue:[^ startIndex]. |
|
2633 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
|
2634 |
]. |
|
2635 |
^ exceptionBlock value |
|
2636 |
||
2637 |
" |
|
2638 |
'one two three four' findMatchString:'o[nu]' |
|
2639 |
'one two three four' findMatchString:'o[nu]' startingAt:3 |
|
2640 |
" |
|
2641 |
! |
|
2642 |
||
608 | 2643 |
includesMatchString:matchString |
2644 |
"like includesString, but allowing match patterns. |
|
2645 |
find matchstring; if found, return true, otherwise return false" |
|
2646 |
||
2647 |
^ (self findMatchString:matchString) ~~ 0 |
|
2648 |
||
2649 |
" |
|
2650 |
'hello world' includesMatchString:'h*' |
|
2651 |
'hello world' includesMatchString:'h[aeiou]llo' |
|
2652 |
'hello world' includesMatchString:'wor*' |
|
2653 |
'hello world' includesMatchString:'woR*' |
|
2654 |
" |
|
2655 |
! |
|
2656 |
||
328 | 2657 |
match:aString |
2658 |
"return true if aString matches self, where self may contain meta-match |
|
2659 |
characters $* (to match any string) or $# (to match any character). |
|
2660 |
or [...] to match a set of characters. |
|
345 | 2661 |
Lower/uppercase are considered different. |
2662 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
2663 |
NOT the ST-80 meaning." |
|
328 | 2664 |
|
2665 |
^ self match:aString from:1 to:aString size ignoreCase:false |
|
2666 |
||
2667 |
" |
|
2668 |
'*ute*' match:'computer' |
|
2669 |
'*uter' match:'computer' |
|
2670 |
'uter*' match:'computer' |
|
2671 |
'*ute*' match:'' |
|
2672 |
'[abcd]*' match:'computer' |
|
2673 |
'[abcd]*' match:'komputer' |
|
2674 |
'*some*compl*ern*' match:'this is some more complicated pattern match' |
|
2675 |
'*some*compl*ern*' match:'this is another complicated pattern match' |
|
2676 |
" |
|
2677 |
! |
|
2678 |
||
2679 |
match:aString from:start to:stop ignoreCase:ignoreCase |
|
2680 |
"return true if part of aString matches myself, |
|
2681 |
where self may contain meta-match |
|
2682 |
characters $* (to match any string) or $# (to match any character) |
|
2683 |
or [...] to match a set of characters. |
|
345 | 2684 |
If ignoreCase is true, lower/uppercase are considered the same. |
2685 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
2686 |
NOT the ST-80 meaning." |
|
328 | 2687 |
|
2688 |
|matchScanArray| |
|
2689 |
||
2690 |
" |
|
2691 |
keep the matchScanArray from the most recent match - |
|
2692 |
avoids parsing the pattern over-and over if multiple searches |
|
2693 |
are done with the same pattern. |
|
2694 |
" |
|
2695 |
(PreviousMatch notNil |
|
2696 |
and:[PreviousMatch key = self]) ifTrue:[ |
|
2697 |
matchScanArray := PreviousMatch value |
|
2698 |
] ifFalse:[ |
|
2699 |
matchScanArray := self class matchScanArrayFrom:self. |
|
2700 |
matchScanArray isNil ifTrue:[ |
|
356 | 2701 |
'CHARARRAY: invalid matchpattern:' infoPrint. self infoPrintNL. |
328 | 2702 |
^ false |
2703 |
]. |
|
2704 |
PreviousMatch := self -> matchScanArray. |
|
2705 |
]. |
|
2706 |
||
2707 |
^ self class |
|
2708 |
matchScan:matchScanArray |
|
2709 |
from:1 to:matchScanArray size |
|
2710 |
with:aString |
|
2711 |
from:start to:stop |
|
2712 |
ignoreCase:ignoreCase |
|
2713 |
||
2714 |
" |
|
2715 |
'*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true |
|
2716 |
'*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true |
|
2717 |
" |
|
359 | 2718 |
! |
2719 |
||
608 | 2720 |
match:aString ignoreCase:ignoreCase |
2721 |
"return true if aString matches self, where self may contain meta-match |
|
2722 |
characters $* (to match any string) or $# (to match any character) |
|
2723 |
or [...] to match a set of characters. |
|
2724 |
If ignoreCase is true, lower/uppercase are considered the same. |
|
2725 |
NOTICE: match-meta character interpretation is like in unix-matching, |
|
2726 |
NOT the ST-80 meaning." |
|
2727 |
||
2728 |
^ self match:aString from:1 to:aString size ignoreCase:ignoreCase |
|
2729 |
||
2730 |
" |
|
2731 |
'*ute*' match:'COMPUTER' ignoreCase:true |
|
2732 |
'*uter' match:'COMPUTER' ignoreCase:false |
|
2733 |
'[abcd]*' match:'computer' ignoreCase:false |
|
2734 |
'[abcd]*' match:'Computer' ignoreCase:false |
|
2735 |
'[a-k]*' match:'komputer' ignoreCase:false |
|
2736 |
'[a-k]*' match:'zomputer' ignoreCase:false |
|
2737 |
'[a-k]*' match:'Komputer' ignoreCase:false |
|
2738 |
'[a-k]*' match:'Komputer' ignoreCase:true |
|
2739 |
'*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true |
|
2740 |
'*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true |
|
2741 |
||
2742 |
Time millisecondsToRun:[ |
|
2743 |
Symbol allInstancesDo:[:sym | |
|
2744 |
'[ab]*' match:sym ignoreCase:false |
|
2745 |
] |
|
2746 |
]. |
|
2747 |
" |
|
2748 |
! ! |
|
2749 |
||
2750 |
!CharacterArray methodsFor:'printing & storing'! |
|
2751 |
||
2752 |
article |
|
2753 |
"return an article string for the receiver." |
|
2754 |
||
2755 |
|firstChar| |
|
2756 |
||
2757 |
firstChar := (self at:1) asLowercase. |
|
2758 |
(firstChar isVowel or:[firstChar == $x]) ifTrue:[ |
|
2759 |
firstChar ~~ $u ifTrue:[ |
|
2760 |
^ 'an' |
|
2761 |
] |
|
2762 |
]. |
|
2763 |
^ 'a' |
|
2764 |
! |
|
2765 |
||
2766 |
displayString |
|
2767 |
"return a string to display the receiver - use storeString to have |
|
2768 |
quotes around." |
|
2769 |
||
2770 |
^ self storeString |
|
2771 |
! |
|
2772 |
||
2773 |
printOn:aStream |
|
2774 |
"print the receiver on aStream" |
|
2775 |
||
2776 |
aStream nextPutAll:self |
|
2777 |
! |
|
2778 |
||
2779 |
printString |
|
2780 |
"return a string for printing - thats myself" |
|
2781 |
||
2782 |
^ self |
|
2783 |
! ! |
|
2784 |
||
2785 |
!CharacterArray methodsFor:'queries'! |
|
2786 |
||
2787 |
encoding |
|
1311 | 2788 |
"return the strings encoding, as a symbol. |
2789 |
Here, by default, we assume #iso8859 encoding. |
|
1241 | 2790 |
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
|
2791 |
|
1311 | 2792 |
^ #iso8859 |
2793 |
||
2794 |
"Modified: 27.4.1996 / 13:23:49 / cg" |
|
608 | 2795 |
! |
2796 |
||
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2797 |
hasChangeOfEmphasis |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2798 |
^ false |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2799 |
|
1381 | 2800 |
"Created: 12.5.1996 / 12:31:39 / cg" |
1375
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2801 |
! |
f035bb7468f5
additions for new Text class
Claus Gittinger <cg@exept.de>
parents:
1333
diff
changeset
|
2802 |
|
608 | 2803 |
isString |
2804 |
"return true, if the receiver is some kind of string; |
|
2805 |
true is returned here - redefinition of Object>>isString." |
|
2806 |
||
2807 |
^ true |
|
1235 | 2808 |
! |
2809 |
||
2810 |
leftIndent |
|
2811 |
"if the receiver starts with spaces, return the number of spaces |
|
2812 |
at the left - otherwise, return 0. |
|
2813 |
If the receiver consists of spaces only, return the receivers size." |
|
2814 |
||
2815 |
|index "{Class: SmallInteger }" |
|
2816 |
end "{Class: SmallInteger }"| |
|
2817 |
||
2818 |
index := 1. |
|
2819 |
end := self size. |
|
2820 |
[index <= end] whileTrue:[ |
|
2821 |
(self at:index) isSeparator ifFalse:[^ index - 1]. |
|
2822 |
index := index + 1 |
|
2823 |
]. |
|
2824 |
^ end |
|
2825 |
||
2826 |
" |
|
2827 |
' hello' leftIndent |
|
2828 |
'foo ' leftIndent |
|
2829 |
' ' leftIndent |
|
2830 |
" |
|
2831 |
||
2832 |
"Modified: 20.4.1996 / 19:28:43 / cg" |
|
608 | 2833 |
! ! |
2834 |
||
2835 |
!CharacterArray methodsFor:'special string converting'! |
|
2836 |
||
2837 |
chopTo:maxLen |
|
2838 |
"if the receivers size is less or equal to maxLen, return it. |
|
2839 |
Otherwise, return a copy of the receiver, where some characters |
|
2840 |
in the middle have been removed for a total string length |
|
2841 |
of maxLen." |
|
2842 |
||
2843 |
|sz n1 n2| |
|
2844 |
||
2845 |
(sz := self size) > maxLen ifTrue:[ |
|
2846 |
n1 := n2 := maxLen // 2. |
|
2847 |
maxLen odd ifTrue:[ |
|
2848 |
n2 := n1 + 1 |
|
2849 |
]. |
|
2850 |
^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1) |
|
2851 |
] |
|
2852 |
||
2853 |
" |
|
2854 |
'12345678901234' chopTo:15 |
|
2855 |
'123456789012345' chopTo:15 |
|
2856 |
'1234567890123456' chopTo:15 |
|
2857 |
'aShortString' chopTo:15 |
|
2858 |
'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 |
|
2859 |
" |
|
2860 |
! |
|
2861 |
||
2862 |
contractAtBeginningTo:maxLen |
|
2863 |
"if the receivers size is less or equal to maxLen, return it. |
|
2864 |
Otherwise, return a copy of the receiver, where some characters |
|
2865 |
at the beginning have been replaced by '...' for a total string length |
|
2866 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
2867 |
||
2868 |
|sz| |
|
2869 |
||
2870 |
(sz := self size) > maxLen ifTrue:[ |
|
2871 |
^ '...' , (self copyFrom:(sz - (maxLen - 4))) |
|
2872 |
] |
|
2873 |
||
2874 |
" |
|
2875 |
'12345678901234' contractAtBeginningTo:15 |
|
2876 |
'123456789012345' contractAtBeginningTo:15 |
|
2877 |
'1234567890123456' contractAtBeginningTo:15 |
|
2878 |
'aShortString' contractAtBeginningTo:15 |
|
2879 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15 |
|
2880 |
" |
|
2881 |
! |
|
359 | 2882 |
|
608 | 2883 |
contractAtEndTo:maxLen |
2884 |
"if the receivers size is less or equal to maxLen, return it. |
|
2885 |
Otherwise, return a copy of the receiver, where some characters |
|
2886 |
at the end have been replaced by '...' for a total string length |
|
2887 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
2888 |
||
2889 |
|sz| |
|
2890 |
||
2891 |
(sz := self size) > maxLen ifTrue:[ |
|
2892 |
^ self copyReplaceFrom:maxLen - 3 |
|
2893 |
with:'...' |
|
2894 |
] |
|
2895 |
||
2896 |
" |
|
2897 |
'12345678901234' contractAtEndTo:15 |
|
2898 |
'123456789012345' contractAtEndTo:15 |
|
2899 |
'1234567890123456' contractAtEndTo:15 |
|
2900 |
'aShortString' contractAtEndTo:15 |
|
2901 |
'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 |
|
2902 |
" |
|
2903 |
! |
|
2904 |
||
2905 |
contractTo:maxLen |
|
2906 |
"if the receivers size is less or equal to maxLen, return it. |
|
2907 |
Otherwise, return a copy of the receiver, where some characters |
|
2908 |
in the middle have been replaced by '...' for a total string length |
|
2909 |
of maxLen. Can be used to abbreviate long entries in tables." |
|
2910 |
||
2911 |
|sz "{ SmallInteger }" |
|
2912 |
halfSize "{ SmallInteger }"| |
|
2913 |
||
2914 |
(sz := self size) > maxLen ifTrue:[ |
|
2915 |
halfSize := maxLen // 2. |
|
2916 |
^ self copyReplaceFrom:halfSize - 1 |
|
2917 |
to:sz - maxLen + halfSize + 1 |
|
2918 |
with:'...' |
|
2919 |
] |
|
2920 |
||
2921 |
" |
|
2922 |
'12345678901234' contractTo:15 |
|
2923 |
'123456789012345' contractTo:15 |
|
2924 |
'1234567890123456' contractTo:15 |
|
2925 |
'aShortString' contractTo:15 |
|
2926 |
'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 |
|
2927 |
" |
|
2928 |
! |
|
2929 |
||
2930 |
expandPlaceholdersWith:argArray |
|
2931 |
"return a copy of the receiver, where all %i escapes are |
|
1308 | 2932 |
replaced by corresponding arguments' printStrings from the argArray. |
608 | 2933 |
I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results |
2934 |
in the new string 'hello world; how is this'. |
|
2935 |
To get a '%' character, use a '%%'-escape. |
|
2936 |
See also bindWith:... for VisualAge compatibility." |
|
2937 |
||
2938 |
|expandedString next |
|
2939 |
idx "{ SmallInteger }" |
|
2940 |
start "{ SmallInteger }" |
|
2941 |
stop "{ SmallInteger }"| |
|
2942 |
||
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2943 |
expandedString := self species new:0. |
608 | 2944 |
stop := self size. |
2945 |
start := 1. |
|
2946 |
[start <= stop] whileTrue:[ |
|
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2947 |
idx := self indexOf:$% startingAt:start. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2948 |
idx == 0 ifTrue:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2949 |
^ expandedString , (self copyFrom:start to:stop) |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2950 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2951 |
"found a %" |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2952 |
expandedString := expandedString , (self copyFrom:start to:(idx - 1)). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2953 |
next := self at:(idx + 1). |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2954 |
(next == $%) ifTrue:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2955 |
expandedString := expandedString , '%' |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2956 |
] ifFalse:[ |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2957 |
expandedString := expandedString , (argArray at:(next digitValue)) printString |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2958 |
]. |
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2959 |
start := idx + 2 |
608 | 2960 |
]. |
2961 |
^ expandedString |
|
2962 |
||
2963 |
" |
|
2964 |
'hello %1' expandPlaceholdersWith:#('world') |
|
2965 |
'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') |
|
2966 |
'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') |
|
1308 | 2967 |
'%1 plus %2 gives %3 ' expandPlaceholdersWith:#(4 5 9) |
608 | 2968 |
" |
1026
455c9f609f4d
care for 16bit strings in expandPlaceHolders
Claus Gittinger <cg@exept.de>
parents:
1025
diff
changeset
|
2969 |
|
1308 | 2970 |
"Modified: 27.4.1996 / 11:58:36 / cg" |
608 | 2971 |
! |
2972 |
||
2973 |
withCRs |
|
2974 |
"return a new string consisting of receivers characters |
|
2975 |
with all \-characters replaced by cr-characters." |
|
2976 |
||
2977 |
^ self copy replaceAll:$\ by:(Character cr) |
|
2978 |
||
2979 |
" |
|
2980 |
'hello\world' withCRs |
|
2981 |
" |
|
2982 |
! |
|
2983 |
||
2984 |
withEscapes |
|
2985 |
"return a new string consisting of receivers characters |
|
2986 |
with all \X-character escapes replaced by corresponding-characters. |
|
2987 |
(similar to the way C-language Strings are converted). |
|
2988 |
The following escapes are supported: |
|
1008 | 2989 |
\r return character |
2990 |
\n newline character |
|
2991 |
\b backspace character |
|
2992 |
\f formfeed character |
|
2993 |
\t tab character |
|
2994 |
\e escape character |
|
2995 |
\\ the \ character itself |
|
2996 |
\nnn three digit octal number defining the characters ascii value |
|
2997 |
\other other |
|
608 | 2998 |
|
2999 |
Notice, that \' is NOT a valid escape, since the general syntax of |
|
3000 |
string constants is not affected by this method. |
|
3001 |
||
3002 |
Although easily implementable, this is NOT done automatically |
|
3003 |
by the compiler (due to a lack of a language standard for this). |
|
3004 |
However, the compiler may detect sends ot #withEscapes to string literals |
|
3005 |
and place a modified string constant into the binary/byte-code. |
|
3006 |
Therefore, no runtime penalty will be payed for using these escapes. |
|
3007 |
(not in pre 2.11 versions) |
|
3008 |
" |
|
3009 |
||
3010 |
|sz "{ SmallInteger }" |
|
3011 |
newSize "{ SmallInteger }" |
|
3012 |
srcIdx "{ SmallInteger }" |
|
3013 |
dstIdx "{ SmallInteger }" |
|
3014 |
val "{ SmallInteger }" |
|
1381 | 3015 |
newString next hasEmphasis e| |
359 | 3016 |
|
3017 |
" |
|
608 | 3018 |
first, count the number of escapes, to allow preallocation |
3019 |
of the new string ... |
|
3020 |
(it is faster to scan the string twice than to reallocate it multiple |
|
3021 |
times in a WriteStream) |
|
3022 |
" |
|
3023 |
sz := newSize := self size. |
|
3024 |
srcIdx := 1. |
|
3025 |
[(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[ |
|
1008 | 3026 |
srcIdx == sz ifFalse:[ |
3027 |
newSize := newSize - 1. |
|
3028 |
srcIdx := srcIdx + 1. |
|
3029 |
next := self at:srcIdx. |
|
3030 |
next == $0 ifTrue:[ |
|
3031 |
[(self at:srcIdx) isDigit] whileTrue:[ |
|
3032 |
newSize := newSize - 1. srcIdx := srcIdx + 1. |
|
3033 |
] |
|
3034 |
]. |
|
3035 |
]. |
|
3036 |
srcIdx := srcIdx + 1. |
|
608 | 3037 |
]. |
3038 |
||
3039 |
newSize == sz ifTrue:[ |
|
1008 | 3040 |
^ self |
608 | 3041 |
]. |
3042 |
||
3043 |
newString := self species new:newSize. |
|
1381 | 3044 |
|
3045 |
hasEmphasis := self hasChangeOfEmphasis. |
|
3046 |
||
608 | 3047 |
" |
3048 |
copy over, replace escapes |
|
3049 |
" |
|
3050 |
srcIdx := dstIdx := 1. |
|
3051 |
[srcIdx <= sz] whileTrue:[ |
|
1008 | 3052 |
next := self at:srcIdx. |
1381 | 3053 |
hasEmphasis ifTrue:[ |
3054 |
e := self emphasisAt:srcIdx |
|
3055 |
]. |
|
1008 | 3056 |
srcIdx := srcIdx + 1. |
3057 |
next == $\ ifTrue:[ |
|
3058 |
srcIdx <= sz ifTrue:[ |
|
3059 |
next := self at:srcIdx. |
|
3060 |
srcIdx := srcIdx + 1. |
|
3061 |
next == $r ifTrue:[ |
|
3062 |
next := Character return |
|
3063 |
] ifFalse:[ |
|
3064 |
next == $n ifTrue:[ |
|
3065 |
next := Character nl |
|
3066 |
] ifFalse:[ |
|
3067 |
next == $b ifTrue:[ |
|
3068 |
next := Character backspace |
|
3069 |
] ifFalse:[ |
|
3070 |
next == $f ifTrue:[ |
|
3071 |
next := Character newPage |
|
3072 |
] ifFalse:[ |
|
3073 |
next == $t ifTrue:[ |
|
3074 |
next := Character tab |
|
3075 |
] ifFalse:[ |
|
3076 |
next == $e ifTrue:[ |
|
3077 |
next := Character esc |
|
3078 |
] ifFalse:[ |
|
3079 |
next == $0 ifTrue:[ |
|
3080 |
val := 0. |
|
3081 |
[next isDigit] whileTrue:[ |
|
3082 |
val := val * 8 + next digitValue. |
|
3083 |
next := self at:srcIdx. |
|
3084 |
srcIdx := srcIdx + 1. |
|
3085 |
]. |
|
3086 |
next := Character value:val. |
|
3087 |
] |
|
3088 |
] |
|
3089 |
] |
|
3090 |
] |
|
3091 |
] |
|
3092 |
] |
|
3093 |
]. |
|
3094 |
]. |
|
3095 |
]. |
|
3096 |
newString at:dstIdx put:next. |
|
1381 | 3097 |
hasEmphasis ifTrue:[ |
3098 |
newString emphasisAt:dstIdx put:e |
|
3099 |
]. |
|
1008 | 3100 |
dstIdx := dstIdx + 1. |
608 | 3101 |
]. |
3102 |
^ newString |
|
3103 |
||
3104 |
" |
|
3105 |
'hello world' withEscapes |
|
3106 |
'hello\world' withEscapes |
|
3107 |
'hello\world\' withEscapes |
|
3108 |
'hello world\' withEscapes |
|
3109 |
'hello\tworld' withEscapes |
|
3110 |
'hello\nworld\na\n\tnice\n\t\tstring' withEscapes |
|
3111 |
'hello\tworld\n' withEscapes |
|
3112 |
'hello\010world' withEscapes |
|
3113 |
'hello\r\nworld' withEscapes |
|
3114 |
" |
|
1008 | 3115 |
|
1381 | 3116 |
"Modified: 12.5.1996 / 12:53:34 / cg" |
608 | 3117 |
! |
3118 |
||
3119 |
withTabs |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3120 |
"return a string consisting of the receivers characters |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3121 |
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
|
3122 |
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
|
3123 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3124 |
Limitation: only the very first spaces are replaced |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3125 |
(i.e. if the receiver contains newLine characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3126 |
no tabs are inserted after those lineBreaks)" |
608 | 3127 |
|
3128 |
|idx "{ SmallInteger }" |
|
3129 |
nTabs "{ SmallInteger }" |
|
3130 |
newString| |
|
3131 |
||
3132 |
idx := self findFirst:[:c | (c ~~ Character space)]. |
|
3133 |
nTabs := (idx-1) // 8. |
|
3134 |
nTabs == 0 ifTrue:[^ self]. |
|
3135 |
||
3136 |
"any tabs" |
|
3137 |
newString := self class new:(self size - (nTabs * 7)). |
|
3138 |
newString atAll:(1 to:nTabs) put:(Character tab). |
|
3139 |
newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1). |
|
3140 |
^ newString |
|
3141 |
||
3142 |
" |
|
3143 |
'12345678901234567890' withTabs |
|
3144 |
' 8901234567890' withTabs |
|
3145 |
' 901234567890' withTabs |
|
3146 |
' 67890' withTabs |
|
3147 |
' 7890' withTabs |
|
3148 |
' 890' withTabs |
|
3149 |
" |
|
3150 |
! |
|
3151 |
||
3152 |
withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3153 |
"return a string consisting of the receivers characters, |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3154 |
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
|
3155 |
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
|
3156 |
otherwise a new string is returned. |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3157 |
This does handle multiline strings." |
608 | 3158 |
|
1381 | 3159 |
|col "{ SmallInteger }" |
3160 |
str ch |
|
3161 |
dstIdx "{ SmallInteger }" |
|
3162 |
newSz "{ SmallInteger }" |
|
3163 |
sz "{ SmallInteger }" |
|
3164 |
hasEmphasis e| |
|
608 | 3165 |
|
3166 |
(self includes:(Character tab)) ifFalse:[^ self]. |
|
1381 | 3167 |
|
3168 |
sz := self size. |
|
3169 |
||
3170 |
"/ count the new size first, instead of |
|
3171 |
"/ multiple resizing (better for large strings) |
|
3172 |
||
3173 |
col := 1. newSz := 0. |
|
3174 |
1 to:sz do:[:srcIdx | |
|
3175 |
ch := self at:srcIdx. |
|
3176 |
ch == Character tab ifFalse:[ |
|
3177 |
col := col + 1. |
|
3178 |
newSz := newSz + 1. |
|
3179 |
ch == Character cr ifTrue:[ |
|
3180 |
col := 1 |
|
3181 |
]. |
|
3182 |
] ifTrue:[ |
|
3183 |
(col \\ 8) to:8 do:[:ii | |
|
3184 |
newSz := newSz + 1. |
|
3185 |
col := col + 1 |
|
3186 |
]. |
|
3187 |
] |
|
608 | 3188 |
]. |
1381 | 3189 |
|
3190 |
str := self species new:newSz. |
|
3191 |
||
3192 |
hasEmphasis := self hasChangeOfEmphasis. |
|
3193 |
||
3194 |
col := 1. dstIdx := 1. |
|
3195 |
1 to:sz do:[:srcIdx | |
|
3196 |
ch := self at:srcIdx. |
|
3197 |
||
3198 |
ch == Character tab ifFalse:[ |
|
3199 |
col := col + 1. |
|
3200 |
ch == Character cr ifTrue:[ |
|
3201 |
col := 1 |
|
3202 |
]. |
|
3203 |
hasEmphasis ifTrue:[ |
|
3204 |
e := self emphasisAt:srcIdx. |
|
3205 |
str emphasisAt:dstIdx put:e |
|
3206 |
]. |
|
3207 |
str at:dstIdx put:ch. |
|
3208 |
dstIdx := dstIdx + 1 |
|
3209 |
] ifTrue:[ |
|
3210 |
(col \\ 8) to:8 do:[:ii | |
|
3211 |
str at:dstIdx put:Character space. |
|
3212 |
dstIdx := dstIdx + 1. |
|
3213 |
col := col + 1 |
|
3214 |
]. |
|
3215 |
] |
|
3216 |
]. |
|
3217 |
^ str |
|
608 | 3218 |
|
3219 |
" |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3220 |
('1' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3221 |
('12345' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3222 |
('123456' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3223 |
('1234567' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3224 |
('12345678' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3225 |
('123456789' , Character tab asString , 'x') withTabsExpanded |
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3226 |
|
608 | 3227 |
(String with:Character tab |
1381 | 3228 |
with:Character tab |
3229 |
with:$1) withTabsExpanded |
|
608 | 3230 |
|
3231 |
(String with:Character tab |
|
1381 | 3232 |
with:$1 |
3233 |
with:Character tab |
|
3234 |
with:$2) withTabsExpanded |
|
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3235 |
|
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3236 |
(String with:Character tab |
1381 | 3237 |
with:$1 |
3238 |
with:Character cr |
|
3239 |
with:Character tab |
|
3240 |
with:$2) withTabsExpanded |
|
608 | 3241 |
" |
735
362ce9e28d89
expandTabs now handles multiline strings
Claus Gittinger <cg@exept.de>
parents:
678
diff
changeset
|
3242 |
|
1381 | 3243 |
"Modified: 12.5.1996 / 13:05:10 / cg" |
608 | 3244 |
! |
3245 |
||
3246 |
withoutCRs |
|
3247 |
"return a new collection consisting of receivers elements |
|
3248 |
with all cr-characters replaced by \-characters. |
|
3249 |
This is the reverse operation of withCRs." |
|
3250 |
||
3251 |
^ self copy replaceAll:(Character cr) by:$\ |
|
3252 |
" |
|
3253 |
'hello |
|
3254 |
world' withoutCRs |
|
359 | 3255 |
" |
608 | 3256 |
! |
3257 |
||
3258 |
withoutLeadingSeparators |
|
3259 |
"return a copy of myself without leading separators. |
|
3260 |
Notice: this does remove tabs, newline or any other whitespace. |
|
3261 |
Returns an empty string, if the receiver consist only of whitespace." |
|
3262 |
||
3263 |
|index| |
|
3264 |
||
3265 |
index := self indexOfNonSeparatorStartingAt:1. |
|
3266 |
index ~~ 0 ifTrue:[ |
|
3267 |
index == 1 ifTrue:[ |
|
3268 |
^ self |
|
3269 |
]. |
|
3270 |
^ self copyFrom:index |
|
3271 |
]. |
|
3272 |
^ '' |
|
3273 |
||
3274 |
" |
|
3275 |
' foo ' withoutLeadingSeparators |
|
3276 |
'foo ' withoutLeadingSeparators |
|
3277 |
' foo' withoutLeadingSeparators |
|
3278 |
' ' withoutLeadingSeparators |
|
3279 |
'foo' withoutLeadingSeparators |
|
3280 |
(' ' , Character tab asString , ' foo ') withoutLeadingSeparators inspect |
|
3281 |
" |
|
3282 |
! |
|
3283 |
||
3284 |
withoutSeparators |
|
3285 |
"return a copy of myself without leading and trailing whitespace. |
|
3286 |
Whitespace is space, tab, newline, formfeed. |
|
3287 |
Use withoutSpaces, if you want to remove spaces only." |
|
3288 |
||
3289 |
|startIndex "{ Class: SmallInteger }" |
|
3290 |
endIndex "{ Class: SmallInteger }" |
|
3291 |
sz| |
|
3292 |
||
3293 |
sz := self size. |
|
3294 |
startIndex := 1. |
|
3295 |
endIndex := sz. |
|
3296 |
||
3297 |
[(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[ |
|
3298 |
startIndex := startIndex + 1 |
|
3299 |
]. |
|
3300 |
[(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[ |
|
3301 |
endIndex := endIndex - 1 |
|
3302 |
]. |
|
3303 |
startIndex > endIndex ifTrue:[ |
|
3304 |
^ '' |
|
3305 |
]. |
|
3306 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
3307 |
^ self |
|
3308 |
]. |
|
3309 |
^ self copyFrom:startIndex to:endIndex |
|
3310 |
||
3311 |
" |
|
3312 |
' foo ' withoutSeparators |
|
3313 |
' foo' withoutSeparators |
|
3314 |
'foo ' withoutSeparators |
|
3315 |
' ' withoutSeparators |
|
3316 |
(' foo' , Character tab asString , ' ') withoutSeparators inspect |
|
3317 |
" |
|
3318 |
! |
|
3319 |
||
3320 |
withoutSpaces |
|
3321 |
"return a copy of myself without leading and trailing spaces. |
|
3322 |
Notice: this does NOT remove tabs, newline or any other whitespace. |
|
3323 |
Use withoutSeparators for this." |
|
3324 |
||
3325 |
|startIndex "{ Class: SmallInteger }" |
|
3326 |
endIndex "{ Class: SmallInteger }" |
|
3327 |
sz| |
|
3328 |
||
3329 |
sz := self size. |
|
3330 |
startIndex := 1. |
|
3331 |
endIndex := sz. |
|
3332 |
||
3333 |
[(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[ |
|
3334 |
startIndex := startIndex + 1 |
|
3335 |
]. |
|
3336 |
[(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[ |
|
3337 |
endIndex := endIndex - 1 |
|
3338 |
]. |
|
3339 |
startIndex > endIndex ifTrue:[ |
|
3340 |
^ '' |
|
3341 |
]. |
|
3342 |
((startIndex == 1) and:[endIndex == sz]) ifTrue:[ |
|
3343 |
^ self |
|
3344 |
]. |
|
3345 |
^ self copyFrom:startIndex to:endIndex |
|
3346 |
||
3347 |
" |
|
3348 |
' foo ' withoutSpaces |
|
3349 |
'foo ' withoutSpaces |
|
3350 |
' foo' withoutSpaces |
|
3351 |
' ' withoutSpaces |
|
3352 |
(' foo' , Character tab asString , ' ') withoutSpaces inspect |
|
3353 |
" |
|
915
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3354 |
! |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3355 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3356 |
withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3357 |
"return a copy of myself without trailing separators. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3358 |
Notice: this does remove tabs, newline or any other whitespace. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3359 |
Returns an empty string, if the receiver consist only of whitespace." |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3360 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3361 |
|index| |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3362 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3363 |
index := self size. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3364 |
[index ~~ 0] whileTrue:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3365 |
(self at:index) isSeparator ifFalse:[ |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3366 |
^ self copyTo:index |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3367 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3368 |
index := index - 1 |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3369 |
]. |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3370 |
^ '' |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3371 |
|
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3372 |
" |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3373 |
' foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3374 |
'foo ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3375 |
' foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3376 |
' ' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3377 |
'foo' withoutTrailingSeparators |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3378 |
(' ' , Character tab asString , ' foo ') withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3379 |
(' foo' , Character tab asString) withoutTrailingSeparators inspect |
1ac1c7e942f4
added withoutTrailingSeparators
Claus Gittinger <cg@exept.de>
parents:
828
diff
changeset
|
3380 |
" |
608 | 3381 |
! ! |
3382 |
||
3383 |
!CharacterArray methodsFor:'substring searching'! |
|
3384 |
||
3385 |
findString:subString |
|
3386 |
"find a substring. if found, return the index; |
|
3387 |
if not found, return 0." |
|
3388 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3389 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:0 |
608 | 3390 |
|
3391 |
" |
|
3392 |
'hello world' findString:'llo' |
|
3393 |
'hello world' findString:'ole' |
|
3394 |
" |
|
3395 |
! |
|
3396 |
||
3397 |
findString:subString ifAbsent:exceptionBlock |
|
3398 |
"find a substring. If found, return the index; |
|
3399 |
if not found, return the result of evaluating exceptionBlock." |
|
3400 |
||
3401 |
^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock |
|
3402 |
! |
|
3403 |
||
3404 |
findString:subString startingAt:index |
|
3405 |
"find a substring, starting at index. if found, return the index; |
|
3406 |
if not found, return 0." |
|
3407 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3408 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:0 |
608 | 3409 |
|
3410 |
" |
|
3411 |
'hello yello' findString:'llo' startingAt:1 |
|
3412 |
'hello yello' findString:'llo' startingAt:5 |
|
3413 |
'hello yello' findString:'llo' startingAt:15 |
|
3414 |
" |
|
3415 |
! |
|
3416 |
||
3417 |
findString:subString startingAt:index ifAbsent:exceptionBlock |
|
3418 |
"find a substring, starting at index. if found, return the index; |
|
3419 |
if not found, return the result of evaluating exceptionBlock." |
|
3420 |
||
3421 |
^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
3422 |
! |
|
3423 |
||
3424 |
includesString:aString |
|
3425 |
"return true, if a substring is contained in the receiver" |
|
3426 |
||
1145
a094d90e11bf
dont use [0] blocks - use 0 constant instead
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3427 |
^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:0) ~~ 0 |
608 | 3428 |
|
3429 |
" |
|
3430 |
'hello world' includesString:'hel' |
|
3431 |
'hello world' includesString:'rld' |
|
3432 |
'hello world' includesString:'llo' |
|
3433 |
'hello world' includesString:'LLO' |
|
3434 |
" |
|
3435 |
! |
|
3436 |
||
3437 |
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock |
|
3438 |
"find a substring, starting at index. if found, return the index; |
|
3439 |
if not found, return the result of evaluating exceptionBlock. |
|
3440 |
This is a q&d hack - not very efficient" |
|
3441 |
||
3442 |
|firstChar found |
|
3443 |
startIndex "{ Class: SmallInteger }" |
|
3444 |
subSize "{ Class: SmallInteger }" |
|
3445 |
mySize "{ Class: SmallInteger }" |
|
3446 |
runIdx "{ Class: SmallInteger }" | |
|
3447 |
||
3448 |
subSize := subString size. |
|
3449 |
subSize == 0 ifTrue:[^ index]. "empty string matches" |
|
3450 |
mySize := self size. |
|
3451 |
firstChar := subString at:1. |
|
3452 |
startIndex := self indexOf:firstChar startingAt:index. |
|
3453 |
[startIndex == 0] whileFalse:[ |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3454 |
runIdx := startIndex. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3455 |
found := true. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3456 |
1 to:subSize do:[:i | |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3457 |
runIdx > mySize ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3458 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3459 |
] ifFalse:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3460 |
(subString at:i) ~= (self at:runIdx) ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3461 |
found := false |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3462 |
] |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3463 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3464 |
runIdx := runIdx + 1 |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3465 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3466 |
found ifTrue:[ |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3467 |
^ startIndex |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3468 |
]. |
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3469 |
startIndex := self indexOf:firstChar startingAt:(startIndex + 1) |
608 | 3470 |
]. |
3471 |
^ exceptionBlock value |
|
1005
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3472 |
|
4507487e0be6
more on encoding/decoding (still unfinished)
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
3473 |
"Modified: 23.2.1996 / 15:35:15 / cg" |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3474 |
! |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3475 |
|
652 | 3476 |
restAfter:keyword withoutSeparators:strip |
651
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3477 |
"compare the left of the receiver with keyword, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3478 |
if it matches return the right. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3479 |
Finally, if strip is true, remove whiteSpace. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3480 |
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
|
3481 |
something: rest |
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
735
diff
changeset
|
3482 |
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
|
3483 |
begins with something. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3484 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3485 |
You may wonder why such a specialized method exists here |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3486 |
- this is so common when processing mailboxes, |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3487 |
rcs files, nntp/pop3 responses, that is was considered worth |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3488 |
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
|
3489 |
times in variuos places." |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3490 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3491 |
|rest| |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3492 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3493 |
(self startsWith:keyword) ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3494 |
rest := self copyFrom:(keyword size + 1). |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3495 |
strip ifTrue:[ |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3496 |
rest := rest withoutSeparators |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3497 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3498 |
^ rest |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3499 |
]. |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3500 |
^ nil |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3501 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3502 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3503 |
'foo: hello world' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3504 |
'funny: something' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3505 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3506 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:true |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3507 |
'foo: hello world ' restAfter:'foo:' withoutSeparators:false |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3508 |
" |
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3509 |
|
2093b018dc3a
added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents:
650
diff
changeset
|
3510 |
"Created: 25.11.1995 / 11:04:18 / cg" |
328 | 3511 |
! ! |
3512 |
||
255 | 3513 |
!CharacterArray methodsFor:'testing'! |
64 | 3514 |
|
3515 |
countWords |
|
3516 |
"return the number of words, which are separated by separators" |
|
3517 |
||
92 | 3518 |
|tally "{ Class: SmallInteger }" |
3519 |
start "{ Class: SmallInteger }" |
|
3520 |
mySize "{ Class: SmallInteger }" |
|
3521 |
stop ch| |
|
64 | 3522 |
|
3523 |
tally := 0. |
|
3524 |
start := 1. |
|
3525 |
mySize := self size. |
|
3526 |
[start <= mySize] whileTrue:[ |
|
154 | 3527 |
ch := self at:start. |
3528 |
ch isSeparator ifTrue:[ |
|
3529 |
start := start + 1 |
|
3530 |
] ifFalse:[ |
|
3531 |
stop := self indexOfSeparatorStartingAt:start. |
|
3532 |
(stop == 0) ifTrue:[ |
|
3533 |
stop := mySize + 1 |
|
3534 |
]. |
|
3535 |
tally := tally + 1. |
|
3536 |
start := stop |
|
3537 |
] |
|
64 | 3538 |
]. |
3539 |
^ tally |
|
3540 |
||
92 | 3541 |
" |
3542 |
'hello world isnt this nice' countWords' |
|
3543 |
" |
|
64 | 3544 |
! |
3545 |
||
1381 | 3546 |
endsWith:aString |
3547 |
"return true, if the receiver ends with something, aString." |
|
3548 |
||
3549 |
|s| |
|
3550 |
||
3551 |
(s := self string) ~~ self ifTrue:[ |
|
3552 |
^ s endsWith:aString |
|
3553 |
]. |
|
3554 |
^ super endsWith:aString |
|
3555 |
||
3556 |
" |
|
3557 |
'hello world' endsWith:'world' |
|
3558 |
'hello world' asText allBold endsWith:'world' |
|
3559 |
" |
|
3560 |
||
3561 |
"Modified: 12.5.1996 / 15:49:18 / cg" |
|
3562 |
! |
|
3563 |
||
608 | 3564 |
isAlphaNumeric |
3565 |
"return true, if the receiver is some alphanumeric word; |
|
3566 |
i.e. consists of a letter followed by letters or digits." |
|
64 | 3567 |
|
608 | 3568 |
self size == 0 ifTrue:[ |
3569 |
"mhmh what is this ?" |
|
3570 |
^ false |
|
64 | 3571 |
]. |
608 | 3572 |
(self at:1) isLetter ifFalse:[^ false]. |
3573 |
self do:[:char | |
|
3574 |
char isLetterOrDigit ifFalse:[^ false]. |
|
3575 |
]. |
|
3576 |
^ true |
|
64 | 3577 |
|
77 | 3578 |
" |
608 | 3579 |
'helloWorld' isAlphaNumeric |
3580 |
'foo1234' isAlphaNumeric |
|
3581 |
'f1234' isAlphaNumeric |
|
3582 |
'1234' isAlphaNumeric |
|
3583 |
'+' isAlphaNumeric |
|
77 | 3584 |
" |
3585 |
! |
|
3586 |
||
608 | 3587 |
isBlank |
3588 |
"return true, if the receiver contains spaces only" |
|
77 | 3589 |
|
608 | 3590 |
self do:[:char | |
3591 |
char ~~ Character space ifTrue:[^ false]. |
|
77 | 3592 |
]. |
608 | 3593 |
^ true |
64 | 3594 |
! |
3595 |
||
3596 |
levenshteinTo:aString |
|
3597 |
"return the levenshtein distance to the argument, aString; |
|
3598 |
this value corrensponds to the number of replacements that have to be |
|
3599 |
made to get aString from the receiver. |
|
196 | 3600 |
See IEEE transactions on Computers 1976 Pg 172 ff." |
64 | 3601 |
|
327 | 3602 |
" |
3603 |
in the following, we assum that ommiting a character |
|
3604 |
is less of an error than inserting an extra character. |
|
3605 |
Therefore the different insertion (i) and deletion (d) |
|
3606 |
values. |
|
3607 |
" |
|
3608 |
||
64 | 3609 |
^ self levenshteinTo:aString s:4 c:1 i:2 d:6 |
154 | 3610 |
|
3611 |
" |
|
3612 |
'ocmprt' levenshteinTo:'computer' |
|
3613 |
'computer' levenshteinTo:'computer' |
|
3614 |
'ocmputer' levenshteinTo:'computer' |
|
3615 |
'cmputer' levenshteinTo:'computer' |
|
327 | 3616 |
'computer' levenshteinTo:'cmputer' |
154 | 3617 |
'Computer' levenshteinTo:'computer' |
3618 |
" |
|
64 | 3619 |
! |
3620 |
||
3621 |
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight |
|
196 | 3622 |
"parametrized levenshtein. |
3623 |
return the levenshtein distance to the argument, aString; |
|
3624 |
this value corrensponds to the number of replacements that have to be |
|
3625 |
made to get aString from the receiver. |
|
3626 |
The arguments are the costs for substitution, case-change, insertion and |
|
3627 |
deletion of a character. |
|
3628 |
See IEEE transactions on Computers 1976 Pg 172 ff" |
|
64 | 3629 |
|
3630 |
|d "delta matrix" |
|
196 | 3631 |
len1 "{ Class: SmallInteger }" |
3632 |
len2 "{ Class: SmallInteger }" |
|
3633 |
dim "{ Class: SmallInteger }" |
|
3634 |
prevRow row col |
|
3635 |
dimPlus1 "{ Class: SmallInteger }" |
|
64 | 3636 |
min pp c1 c2| |
3637 |
||
3638 |
len1 := self size. |
|
3639 |
len2 := aString size. |
|
3640 |
||
3641 |
"create the help-matrix" |
|
3642 |
||
3643 |
dim := len1 max:len2. |
|
3644 |
dimPlus1 := dim + 1. |
|
3645 |
||
3646 |
d := Array new:dimPlus1. |
|
3647 |
1 to:dimPlus1 do:[:i | |
|
154 | 3648 |
d at:i put:(Array new:dimPlus1) |
64 | 3649 |
]. |
3650 |
||
3651 |
"init help-matrix" |
|
3652 |
||
3653 |
(d at:1) at:1 put:0. |
|
3654 |
row := d at:1. |
|
3655 |
1 to:dim do:[:j | |
|
154 | 3656 |
row at:(j + 1) put:( (row at:j) + insrtWeight ) |
64 | 3657 |
]. |
3658 |
||
3659 |
1 to:dim do:[:i | |
|
154 | 3660 |
(d at:(i + 1)) at:1 put:( ((d at:i) at:1) + deleteWeight ) |
64 | 3661 |
]. |
3662 |
||
3663 |
1 to:len1 do:[:i | |
|
154 | 3664 |
c1 := self at:i. |
3665 |
1 to:len2 do:[:j | |
|
3666 |
c2 := aString at:j. |
|
3667 |
(c1 == c2) ifTrue:[ |
|
3668 |
pp := 0 |
|
3669 |
] ifFalse:[ |
|
3670 |
(c1 asLowercase == c2 asLowercase) ifTrue:[ |
|
3671 |
pp := caseWeight |
|
3672 |
] ifFalse:[ |
|
3673 |
pp := substWeight |
|
3674 |
] |
|
3675 |
]. |
|
3676 |
prevRow := d at:i. |
|
3677 |
row := d at:(i + 1). |
|
3678 |
col := j + 1. |
|
3679 |
min := (prevRow at:j) + pp. |
|
3680 |
min := min min:( (row at:j) + insrtWeight). |
|
3681 |
min := min min:( (prevRow at:col) + deleteWeight). |
|
3682 |
row at:col put: min |
|
3683 |
] |
|
64 | 3684 |
]. |
3685 |
||
3686 |
^ (d at:(len1 + 1)) at:(len2 + 1) |
|
3687 |
! |
|
3688 |
||
608 | 3689 |
numArgs |
3690 |
"treating the receiver as a message selector, return how many arguments would it take" |
|
3691 |
||
3692 |
|binopChars| |
|
3693 |
||
3694 |
(self size > 2) ifFalse:[ |
|
3695 |
binopChars := '|&-+=*/\<>~@,'. |
|
3696 |
(self size == 1) ifTrue:[ |
|
3697 |
((binopChars occurrencesOf:(self at:1)) == 0) ifTrue:[^ 0]. |
|
3698 |
^ 1 |
|
3699 |
]. |
|
3700 |
((binopChars occurrencesOf:(self at:1)) == 0) ifFalse:[ |
|
3701 |
((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1] |
|
3702 |
] |
|
3703 |
]. |
|
3704 |
^ self occurrencesOf:$: |
|
3705 |
||
3706 |
" |
|
3707 |
'foo:bar:' numArgs |
|
3708 |
#foo:bar: numArgs |
|
3709 |
'hello' numArgs |
|
3710 |
'+' numArgs |
|
3711 |
" |
|
3712 |
! |
|
3713 |
||
3714 |
partsIfSelector |
|
3715 |
"treat the receiver as a message selector, return a collection of parts." |
|
3716 |
||
3717 |
|idx1 "{ Class: SmallInteger }" |
|
3718 |
coll idx2 sz| |
|
3719 |
||
3720 |
coll := OrderedCollection new. |
|
3721 |
idx1 := 1. |
|
3722 |
sz := self size. |
|
3723 |
[true] whileTrue:[ |
|
3724 |
idx2 := self indexOf:$: startingAt:idx1 + 1. |
|
3725 |
(idx2 == 0 or:[idx2 == sz]) ifTrue:[ |
|
3726 |
coll add:(self copyFrom:idx1). |
|
3727 |
^ coll |
|
3728 |
]. |
|
3729 |
coll add:(self copyFrom:idx1 to:idx2). |
|
3730 |
idx1 := idx2 + 1 |
|
3731 |
]. |
|
3732 |
||
3733 |
" |
|
3734 |
'foo:bar:' partsIfSelector |
|
3735 |
#foo:bar: partsIfSelector |
|
3736 |
'hello' partsIfSelector |
|
3737 |
'+' partsIfSelector |
|
3738 |
" |
|
3739 |
! |
|
3740 |
||
64 | 3741 |
spellAgainst: aString |
3742 |
"return an integer between 0 and 100 indicating how similar |
|
154 | 3743 |
the argument is to the receiver. No case conversion is done. |
3744 |
This algorithm is much simpler (but also less exact) than the |
|
3745 |
levenshtein distance. Experiment which is better for your |
|
3746 |
application." |
|
64 | 3747 |
|
3748 |
| i1 "{ Class: SmallInteger }" |
|
3749 |
i2 "{ Class: SmallInteger }" |
|
154 | 3750 |
next1 "{ Class: SmallInteger }" |
3751 |
next2 "{ Class: SmallInteger }" |
|
64 | 3752 |
size1 "{ Class: SmallInteger }" |
3753 |
size2 "{ Class: SmallInteger }" |
|
3754 |
score "{ Class: SmallInteger }" |
|
3755 |
maxLen "{ Class: SmallInteger }" | |
|
3756 |
||
3757 |
size1 := self size. |
|
3758 |
size2 := aString size. |
|
154 | 3759 |
maxLen := size1 max:size2. |
64 | 3760 |
score := 0. |
3761 |
i1 := i2 := 1. |
|
3762 |
[i1 <= size1 and: [i2 <= size2]] whileTrue:[ |
|
154 | 3763 |
next1 := i1 + 1. |
3764 |
next2 := i2 + 1. |
|
3765 |
(self at:i1) == (aString at:i2) ifTrue: [ |
|
3766 |
score := score+1. |
|
3767 |
i1 := next1. |
|
3768 |
i2 := next2 |
|
3769 |
] ifFalse: [ |
|
3770 |
(i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [ |
|
3771 |
i2 := next2 |
|
3772 |
] ifFalse: [ |
|
3773 |
(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [ |
|
3774 |
i1 := next1 |
|
3775 |
] ifFalse: [ |
|
3776 |
i1 := next1. |
|
3777 |
i2 := next2 |
|
3778 |
] |
|
3779 |
] |
|
3780 |
] |
|
64 | 3781 |
]. |
3782 |
||
1124 | 3783 |
score == maxLen ifTrue: [^ 100]. |
154 | 3784 |
^ 100 * score // maxLen |
64 | 3785 |
|
154 | 3786 |
" |
3787 |
'Smalltalk' spellAgainst: 'Smalltlak' |
|
3788 |
'Smalltalk' spellAgainst: 'smalltlak' |
|
3789 |
'Smalltalk' spellAgainst: 'smalltalk' |
|
3790 |
'Smalltalk' spellAgainst: 'smalltlk' |
|
3791 |
'Smalltalk' spellAgainst: 'Smalltolk' |
|
3792 |
" |
|
1381 | 3793 |
! |
3794 |
||
3795 |
startsWith:aString |
|
3796 |
"return true, if the receiver starts with something, aString." |
|
3797 |
||
3798 |
|s| |
|
3799 |
||
3800 |
(s := self string) ~~ self ifTrue:[ |
|
3801 |
^ s startsWith:aString |
|
3802 |
]. |
|
3803 |
^ super startsWith:aString |
|
3804 |
||
3805 |
" |
|
3806 |
'hello world' startsWith:'hello' |
|
3807 |
'hello world' asText allBold startsWith:'hello' |
|
3808 |
" |
|
3809 |
||
3810 |
"Created: 12.5.1996 / 15:46:40 / cg" |
|
3811 |
"Modified: 12.5.1996 / 15:49:24 / cg" |
|
64 | 3812 |
! ! |
3813 |
||
629 | 3814 |
!CharacterArray class methodsFor:'documentation'! |
3815 |
||
3816 |
version |
|
1381 | 3817 |
^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.84 1996-05-12 14:47:30 cg Exp $' |
629 | 3818 |
! ! |