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