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