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