author | Stefan Vogel <sv@exept.de> |
Wed, 04 Aug 1999 16:13:32 +0200 | |
changeset 4527 | 2ddbe34bab87 |
parent 4340 | 523ef8410fad |
child 4655 | b9405ca0bb4e |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
154 | 3 |
All Rights Reserved |
1 | 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 |
||
13 |
Magnitude subclass:#Character |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
14 |
instanceVariableNames:'asciivalue' |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
15 |
classVariableNames:'CharacterTable' |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
16 |
poolDictionaries:'' |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
17 |
category:'Magnitude-General' |
1 | 18 |
! |
19 |
||
2124 | 20 |
!Character class methodsFor:'documentation'! |
54 | 21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
154 | 25 |
All Rights Reserved |
88 | 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 |
||
54 | 36 |
documentation |
37 |
" |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
38 |
This class represents characters. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
39 |
Notice, that actual character objects are not used when characters |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
40 |
are stored in strings, symbols or twoByteStrings; these only store |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
41 |
a characters asciiValue for a more compact representation. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
42 |
The word 'asciiValue' is a historic leftover - actually, any integer |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
43 |
code is allowed (i.e. characters are not limited to 8bit). |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
44 |
|
1229 | 45 |
Single byte Characters are unique; |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
46 |
i.e. for every asciiValue (0..255) there exists exactly one instance of |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
47 |
Character, which is shared (Character value:xxx checks for this, and returns |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
48 |
a reference to an existing instance). |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
49 |
Other characters (i.e. asciivalue > 255) are not shared; i.e. these |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
50 |
are created as required. |
1 | 51 |
|
1229 | 52 |
This means: you may compare characters using #== ONLY IFF you are certain, |
357 | 53 |
that the characters ranges is 0..255. Otherwise, you HAVE TO compare |
54 |
using #=. (if in doubt, always compare using #=). |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
55 |
Sorry for this inconvenience, but it is (practically) impossible to keep |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
56 |
the possible maximum of 2^32 characters (Unicode) around, for that |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
57 |
convenience alone. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
58 |
|
357 | 59 |
|
68 | 60 |
Methods marked as (JS) come from the manchester Character goody |
61 |
(CharacterComparing) by Jan Steinman, which allow Characters to be used as |
|
1229 | 62 |
Interval elements (i.e. ($a to:$z) do:[...] ); |
63 |
They are not a big deal, but convenient add-ons. |
|
64 |
Some of these have been modified a bit. |
|
1 | 65 |
|
68 | 66 |
WARNING: characters are known by compiler and runtime system - |
1229 | 67 |
do not change the instance layout. |
357 | 68 |
|
69 |
Also, although you can create subclasses of Character, the compiler always |
|
70 |
creates instances of Character for literals ... |
|
814
d4d28ca7afcd
made the global CharacterTable a classVar of Character
Claus Gittinger <cg@exept.de>
parents:
760
diff
changeset
|
71 |
... and other classes are hard-wired to always return instances of characters |
357 | 72 |
in some cases (i.e. String>>at:, Symbol>>at: etc.). |
73 |
Therefore, it may not make sense to create a character-subclass. |
|
1295 | 74 |
|
75 |
[author:] |
|
76 |
Claus Gittinger |
|
77 |
||
78 |
[see also:] |
|
79 |
String TwoByteString |
|
80 |
StringCollection |
|
54 | 81 |
" |
82 |
! ! |
|
1 | 83 |
|
2124 | 84 |
!Character class methodsFor:'instance creation'! |
1 | 85 |
|
86 |
basicNew |
|
87 |
"catch new - Characters cannot be created with new" |
|
88 |
||
89 |
^ self error:'Characters cannot be created with new' |
|
90 |
! |
|
91 |
||
699 | 92 |
digitValue:anInteger |
93 |
"return a character that corresponds to anInteger. |
|
94 |
0-9 map to $0-$9, 10-35 map to $A-$Z" |
|
95 |
||
96 |
|val "{ Class: SmallInteger }" | |
|
97 |
||
98 |
val := anInteger. |
|
99 |
(val between:0 and:9) ifTrue:[ |
|
100 |
^ Character value:(val + ($0 asciiValue)) |
|
101 |
]. |
|
102 |
(val between:10 and:35) ifTrue:[ |
|
103 |
^ Character value:(val + ($A asciiValue - 10)) |
|
104 |
]. |
|
105 |
^self error:'value not in range 0 to 35' |
|
106 |
! |
|
107 |
||
1 | 108 |
value:anInteger |
109 |
"return a character with asciivalue anInteger" |
|
110 |
||
111 |
%{ /* NOCONTEXT */ |
|
112 |
||
54 | 113 |
INT ascii; |
1 | 114 |
|
249 | 115 |
if (__isSmallInteger(anInteger)) { |
116 |
ascii = __intVal(anInteger); |
|
154 | 117 |
if ((ascii & ~0xFF) == 0 /* (ascii >= 0) && (ascii <= 255) */) |
1133 | 118 |
RETURN ( __MKCHARACTER(ascii) ); |
1 | 119 |
} |
819 | 120 |
%}. |
1 | 121 |
(anInteger between:0 and:16rFF) ifTrue:[ |
154 | 122 |
^ CharacterTable at:(anInteger + 1) |
1 | 123 |
]. |
124 |
(anInteger between:16r100 and:16rFFFF) ifTrue:[ |
|
154 | 125 |
^ super basicNew setAsciiValue:anInteger |
1 | 126 |
]. |
357 | 127 |
" |
128 |
a characters ascii-code must be 0..16rFFFF. |
|
129 |
(i.e. only single-byte and twoByte characters are allowed.) |
|
130 |
" |
|
1 | 131 |
self error:'invalid ascii code for character' |
699 | 132 |
! ! |
133 |
||
2214 | 134 |
!Character class methodsFor:'accessing untypeable characters'! |
135 |
||
136 |
endOfInput |
|
137 |
"Answer the Character representing ctrl-d ." |
|
138 |
||
139 |
^self value: 4 |
|
140 |
! |
|
141 |
||
142 |
leftParenthesis |
|
143 |
"Answer the Character representing a left parenthesis." |
|
144 |
||
145 |
^self value: 40 |
|
146 |
! |
|
147 |
||
148 |
period |
|
149 |
"Answer the Character representing a carriage period." |
|
150 |
||
151 |
^self value: 46 |
|
152 |
! |
|
153 |
||
154 |
poundSign |
|
155 |
"Answer the Character representing a pound sign." |
|
156 |
||
157 |
^self value: 35 |
|
158 |
! |
|
159 |
||
160 |
rightParenthesis |
|
161 |
"Answer the Character representing a right parenthesis." |
|
162 |
||
163 |
^self value: 41 |
|
164 |
! ! |
|
165 |
||
2124 | 166 |
!Character class methodsFor:'constants'! |
699 | 167 |
|
168 |
backspace |
|
169 |
"return the backspace character" |
|
170 |
||
171 |
^ Character value:8 |
|
172 |
! |
|
173 |
||
174 |
bell |
|
175 |
"return the bell character" |
|
176 |
||
177 |
^ Character value:7 |
|
178 |
! |
|
179 |
||
180 |
cr |
|
181 |
"return the lineEnd character |
|
182 |
- actually (in unix) this is a newline character" |
|
183 |
||
184 |
^ Character value:10 |
|
185 |
! |
|
186 |
||
187 |
del |
|
188 |
"return the delete character" |
|
189 |
||
190 |
^ Character value:16r7F |
|
191 |
! |
|
192 |
||
193 |
doubleQuote |
|
194 |
"return the double-quote character" |
|
195 |
||
196 |
^ Character value:34 |
|
197 |
! |
|
198 |
||
199 |
esc |
|
200 |
"return the escape character" |
|
201 |
||
202 |
^ Character value:27 |
|
203 |
! |
|
204 |
||
205 |
excla |
|
206 |
"return the exclamation-mark character" |
|
207 |
^ $!! |
|
1 | 208 |
! |
209 |
||
699 | 210 |
ff |
211 |
"return the form-feed character" |
|
212 |
||
213 |
^ Character value:12 |
|
214 |
! |
|
215 |
||
216 |
lf |
|
217 |
"return the newline/linefeed character" |
|
218 |
||
219 |
^ Character value:10 |
|
220 |
! |
|
1 | 221 |
|
4340
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
222 |
linefeed |
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
223 |
"squeak compatibility: return the newline/linefeed character" |
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
224 |
|
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
225 |
^ Character value:10 |
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
226 |
! |
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
227 |
|
699 | 228 |
maxValue |
229 |
"return the maximum asciiValue a character can have" |
|
230 |
||
231 |
^ 16rFFFF |
|
232 |
! |
|
233 |
||
234 |
newPage |
|
235 |
"return the form-feed character" |
|
236 |
||
237 |
^ Character value:12 |
|
238 |
! |
|
239 |
||
240 |
nl |
|
241 |
"return the newline character" |
|
68 | 242 |
|
699 | 243 |
^ Character value:10 |
244 |
! |
|
245 |
||
246 |
quote |
|
247 |
"return the single-quote character" |
|
248 |
||
249 |
^ Character value:39 |
|
250 |
! |
|
251 |
||
252 |
return |
|
253 |
"return the return character. |
|
254 |
In ST/X, this is different from cr - for Unix reasons." |
|
255 |
||
256 |
^ Character value:13 |
|
257 |
! |
|
258 |
||
259 |
space |
|
260 |
"return the blank character" |
|
261 |
||
262 |
^ Character value:32 |
|
263 |
! |
|
264 |
||
265 |
tab |
|
266 |
"return the tabulator character" |
|
267 |
||
268 |
^ Character value:9 |
|
1 | 269 |
! ! |
270 |
||
2124 | 271 |
!Character class methodsFor:'primitive input'! |
1 | 272 |
|
273 |
fromUser |
|
357 | 274 |
"return a character from the keyboard (C's standard input stream) |
1 | 275 |
- this should only be used for emergency evaluators and the like." |
276 |
||
277 |
%{ /* NOCONTEXT */ |
|
278 |
int c; |
|
279 |
||
280 |
c = getchar(); |
|
281 |
if (c < 0) { |
|
154 | 282 |
RETURN (nil); |
1 | 283 |
} |
1133 | 284 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
1 | 285 |
%} |
286 |
! ! |
|
287 |
||
2124 | 288 |
!Character class methodsFor:'queries'! |
3 | 289 |
|
4337
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
290 |
allCharacters |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
291 |
"added for squeak compatibility: return a collection of all chars" |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
292 |
|
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
293 |
^ CharacterTable |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
294 |
|
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
295 |
" |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
296 |
Character allCharacters |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
297 |
" |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
298 |
! |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
299 |
|
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
300 |
hasImmediateInstances |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
301 |
"return true if this class has immediate instances. |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
302 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
303 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
304 |
^ self == Character |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
305 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
306 |
"Created: 3.6.1997 / 12:01:52 / cg" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
307 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
308 |
|
3 | 309 |
isBuiltInClass |
1271 | 310 |
"return true if this class is known by the run-time-system. |
311 |
Here, true is returned for myself, false for subclasses." |
|
3 | 312 |
|
313 |
^ self == Character |
|
1271 | 314 |
|
315 |
"Modified: 23.4.1996 / 15:56:39 / cg" |
|
4337
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
316 |
! |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
317 |
|
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
318 |
separators |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
319 |
"added for squeak compatibility: return a collection of separator chars" |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
320 |
|
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
321 |
^ Array |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
322 |
with:Character space |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
323 |
with:Character cr |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
324 |
with:Character tab |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
325 |
with:Character lf |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
326 |
with:Character ff |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
327 |
|
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
328 |
" |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
329 |
Character separators |
07fad5b7af9b
added #allCharacters & #separators for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4037
diff
changeset
|
330 |
" |
3 | 331 |
! ! |
332 |
||
1 | 333 |
!Character methodsFor:'accessing'! |
334 |
||
335 |
asciiValue |
|
54 | 336 |
"return the asciivalue of myself. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
337 |
The name 'asciiValue' is a historic leftover - characters are not |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
338 |
limited to 8bit characters. |
54 | 339 |
PP has removed this methhod with 4.1 and providing |
340 |
asInteger instead." |
|
1 | 341 |
|
342 |
^asciivalue |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
343 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
344 |
"Modified: 27.6.1996 / 12:34:34 / cg" |
1 | 345 |
! |
346 |
||
347 |
instVarAt:index put:anObject |
|
54 | 348 |
"catch instvar access - asciivalue may not be changed" |
1 | 349 |
|
350 |
self error:'Characters may not be modified' |
|
2214 | 351 |
! |
352 |
||
353 |
newDigitValue |
|
354 |
"Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0 otherwise. |
|
355 |
This is used to parse literal numbers of radix 2-36." |
|
356 |
||
357 |
| code value | |
|
358 |
code := self asInteger. |
|
359 |
value := code - $0 asInteger. |
|
360 |
value <= 9 ifTrue: [^value]. |
|
361 |
value := code - $A asInteger. |
|
362 |
(value >= 0 and: [value < 26]) |
|
363 |
ifTrue: [^value + 10]. |
|
364 |
^-1 |
|
1 | 365 |
! ! |
366 |
||
699 | 367 |
!Character methodsFor:'arithmetic'! |
1 | 368 |
|
369 |
+ aMagnitude |
|
370 |
"Return the Character that is <aMagnitude> higher than the receiver. |
|
371 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
372 |
||
2 | 373 |
^ Character value:(asciivalue + aMagnitude asInteger \\ 256) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
374 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
375 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
376 |
$A + 5 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
377 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
378 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
379 |
"Modified: 27.6.1996 / 12:34:51 / cg" |
1 | 380 |
! |
381 |
||
382 |
- aMagnitude |
|
383 |
"Return the Character that is <aMagnitude> lower than the receiver. |
|
68 | 384 |
Wrap if the resulting value is not a legal Character value. (JS) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
385 |
claus: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
386 |
modified to return the difference as integer, if the argument |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
387 |
is another character. If the argument is a number, a character is |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
388 |
returned." |
1 | 389 |
|
68 | 390 |
aMagnitude isCharacter ifTrue:[ |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
391 |
^ self asciiValue - aMagnitude asciiValue |
68 | 392 |
]. |
2 | 393 |
^ Character value:(asciivalue - aMagnitude asInteger \\ 256) |
68 | 394 |
|
395 |
" |
|
396 |
$z - $a |
|
397 |
$d - 3 |
|
398 |
" |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
399 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
400 |
"Modified: 27.6.1996 / 12:35:34 / cg" |
1 | 401 |
! |
402 |
||
403 |
// aMagnitude |
|
404 |
"Return the Character who's value is the receiver divided by <aMagnitude>. |
|
405 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
406 |
||
2 | 407 |
^ Character value:(asciivalue // aMagnitude asInteger \\ 256) |
1 | 408 |
! |
409 |
||
410 |
\\ aMagnitude |
|
411 |
"Return the Character who's value is the receiver modulo <aMagnitude>. |
|
412 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
413 |
||
2 | 414 |
^ Character value:(asciivalue \\ aMagnitude asInteger \\ 256) |
1 | 415 |
! ! |
416 |
||
699 | 417 |
!Character methodsFor:'binary storage'! |
418 |
||
419 |
hasSpecialBinaryRepresentation |
|
420 |
"return true, if the receiver has a special binary representation" |
|
421 |
||
422 |
^ true |
|
423 |
! |
|
424 |
||
425 |
storeBinaryOn:stream manager:manager |
|
426 |
"store a binary representation of the receiver on stream; |
|
427 |
redefined, since single-byte characters are stored more compact |
|
428 |
with a special type-code followed by the asciiValue." |
|
429 |
||
430 |
(asciivalue < 256) ifTrue:[ |
|
3072 | 431 |
stream nextPut:manager codeForCharacter; nextPut:asciivalue. |
699 | 432 |
] ifFalse:[ |
3072 | 433 |
stream nextPut:manager codeForTwoByteCharacter. |
434 |
stream nextPutShort:asciivalue MSB:true |
|
699 | 435 |
] |
3072 | 436 |
|
437 |
"Modified: / 2.11.1997 / 14:14:50 / cg" |
|
699 | 438 |
! ! |
439 |
||
440 |
!Character methodsFor:'comparing'! |
|
441 |
||
442 |
< aCharacter |
|
443 |
"return true, if the arguments asciiValue is greater than mine" |
|
444 |
||
445 |
^ (asciivalue < aCharacter asciiValue) |
|
446 |
! |
|
447 |
||
448 |
<= aCharacter |
|
449 |
"return true, if the arguments asciiValue is greater or equal to mine" |
|
450 |
||
451 |
^ (asciivalue <= aCharacter asciiValue) |
|
452 |
! |
|
453 |
||
454 |
= aCharacter |
|
455 |
"return true, if the argument, aCharacter is the same character |
|
456 |
Redefined to take care of 16bit characters." |
|
457 |
||
458 |
self == aCharacter ifTrue:[^ true]. |
|
459 |
aCharacter isCharacter ifFalse:[^ false]. |
|
460 |
^ (asciivalue = aCharacter asciiValue) |
|
461 |
! |
|
462 |
||
463 |
> aCharacter |
|
464 |
"return true, if the arguments asciiValue is less than mine" |
|
465 |
||
466 |
^ (asciivalue > aCharacter asciiValue) |
|
467 |
! |
|
468 |
||
469 |
>= aCharacter |
|
470 |
"return true, if the arguments asciiValue is less or equal to mine" |
|
471 |
||
472 |
^ (asciivalue >= aCharacter asciiValue) |
|
473 |
! |
|
474 |
||
475 |
identityHash |
|
476 |
"return an integer useful for hashing on identity" |
|
477 |
||
478 |
asciivalue <= 255 ifTrue:[ |
|
479 |
^ 4096 + asciivalue |
|
480 |
]. |
|
481 |
^ super identityHash |
|
482 |
! |
|
483 |
||
484 |
sameAs:aCharacter |
|
485 |
"return true, if the argument, aCharacter is the same character, |
|
486 |
ignoring case differences." |
|
487 |
||
488 |
self == aCharacter ifTrue:[^ true]. |
|
489 |
^ self asLowercase = aCharacter asLowercase |
|
490 |
! |
|
491 |
||
492 |
~= aCharacter |
|
493 |
"return true, if the argument, aCharacter is not the same character |
|
494 |
Redefined to take care of 16bit characters." |
|
495 |
||
496 |
self == aCharacter ifTrue:[^ false]. |
|
497 |
aCharacter isCharacter ifFalse:[^ true]. |
|
498 |
^ (asciivalue ~~ aCharacter asciiValue) |
|
499 |
! ! |
|
500 |
||
501 |
!Character methodsFor:'converting'! |
|
502 |
||
503 |
asCharacter |
|
504 |
"usually sent to integers, but redefined here to allow integers |
|
505 |
and characters to be used commonly without a need for a test." |
|
506 |
||
507 |
^ self |
|
508 |
||
509 |
" |
|
510 |
32 asCharacter |
|
511 |
" |
|
512 |
! |
|
513 |
||
514 |
asInteger |
|
515 |
"return an Integer with my ascii-value. |
|
516 |
OWST4.2 compatibility (sigh)" |
|
517 |
||
518 |
^ asciivalue |
|
519 |
! |
|
520 |
||
521 |
asLowercase |
|
522 |
"return a character with same letter as the receiver, |
|
523 |
but lowercase (the receiver if its lowercase or nonLetter)" |
|
524 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
525 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
526 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
527 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
528 |
"/ self isUppercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
529 |
"/ ^ Character value:(asciivalue + 32) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
530 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
531 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
532 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
533 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
534 |
((code >= $A asciiValue) and:[code <= $Z asciiValue]) ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
535 |
^ Character value:(code + ($a asciiValue - $A asciiValue)) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
536 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
537 |
code < 16r00C0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
538 |
code < 16r0100 ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
539 |
code >= 16r00DF ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
540 |
code == 16r00D7 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
541 |
^ Character value:(code + 16r20) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
542 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
543 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
544 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
545 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
546 |
|
2124 | 547 |
'Character [info]: Unicode support is under construction' infoPrintCR. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
548 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
549 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
550 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
551 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
552 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
553 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
554 |
|
2124 | 555 |
"Modified: 10.1.1997 / 15:35:44 / cg" |
699 | 556 |
! |
557 |
||
558 |
asString |
|
559 |
"return a string of len 1 with myself as contents" |
|
560 |
||
561 |
%{ /* NOCONTEXT */ |
|
562 |
char buffer[2]; |
|
563 |
OBJ s; |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
564 |
unsigned val; |
699 | 565 |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
566 |
val = __intVal(_characterVal(self)); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
567 |
if (val <= 0xFF) { |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
568 |
buffer[0] = (char) val; |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
569 |
buffer[1] = '\0'; |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
570 |
s = __MKSTRING_L(buffer, 1 COMMA_SND); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
571 |
if (s != nil) { |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
572 |
RETURN (s); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
573 |
} |
699 | 574 |
} |
575 |
%}. |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
576 |
asciivalue > 255 ifTrue:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
577 |
^ (TwoByteString new:1) at:1 put:self; yourself |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
578 |
]. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
579 |
|
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
580 |
"/ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
581 |
"/ ^ (String new:1) at:1 put:self; yourself. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
582 |
"/ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
583 |
|
699 | 584 |
" |
585 |
memory allocation (for the new string) failed. |
|
586 |
When we arrive here, there was no memory, even after a garbage collect. |
|
587 |
This means, that the VM wanted to get some more memory from the |
|
588 |
OS, which was not kind enough to give it. |
|
589 |
Bad luck - you should increase the swap space on your machine. |
|
590 |
" |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
591 |
|
699 | 592 |
^ ObjectMemory allocationFailureSignal raise. |
593 |
! |
|
594 |
||
595 |
asSymbol |
|
596 |
"return a unique symbol which prints like I print" |
|
597 |
||
598 |
^ Symbol internCharacter:self |
|
599 |
! |
|
600 |
||
601 |
asUppercase |
|
602 |
"return a character with same letter as the receiver, |
|
603 |
but uppercase (the receiver if its uppercase or nonLetter)" |
|
604 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
605 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
606 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
607 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
608 |
"/ self isLowercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
609 |
"/ ^ Character value:(asciivalue - 32) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
610 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
611 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
612 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
613 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
614 |
((code >= $a asciiValue) and:[code <= $z asciiValue]) ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
615 |
^ Character value:(code + ($A asciiValue - $a asciiValue)) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
616 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
617 |
code < 16r00E0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
618 |
code < 16r0100 ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
619 |
code == 16r00F7 ifTrue:[^ self]. "/ division |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
620 |
"/ code == 16r00FF ifTrue:[^ Character value:16r0178]. "/ y diaresis (no uppercase equivalent in ISO-latin 1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
621 |
code == 16r00FF ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
622 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
623 |
^ Character value:(code - 16r20) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
624 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
625 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
626 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
627 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
628 |
|
2124 | 629 |
'Character [info]: Unicode support is under construction' infoPrintCR. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
630 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
631 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
632 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
633 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
634 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
635 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
636 |
|
2124 | 637 |
"Modified: 10.1.1997 / 15:35:51 / cg" |
699 | 638 |
! |
639 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
640 |
decodeAsLiteralArray |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
641 |
"given a literalEncoding in the receiver, |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
642 |
create & return the corresponding object. |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
643 |
The inverse operation to #literalArrayEncoding." |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
644 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
645 |
^ self |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
646 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
647 |
"Created: / 27.10.1997 / 14:40:16 / cg" |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
648 |
! |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
649 |
|
699 | 650 |
digitValue |
651 |
"return my digitValue for any base" |
|
652 |
||
653 |
|ascii "{ Class: SmallInteger }" | |
|
654 |
||
655 |
ascii := asciivalue. |
|
656 |
(ascii between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[ |
|
657 |
^ ascii - $0 asciiValue |
|
658 |
]. |
|
659 |
(ascii between:($a asciiValue) and:($z asciiValue)) ifTrue:[ |
|
660 |
^ ascii + (10 - $a asciiValue) |
|
661 |
]. |
|
662 |
(ascii between:($A asciiValue) and:($Z asciiValue)) ifTrue:[ |
|
663 |
^ ascii + (10 - $A asciiValue) |
|
664 |
]. |
|
665 |
||
666 |
"remove error below for X3J20 conformance ... " |
|
667 |
self error:'bad character'. |
|
668 |
" " |
|
669 |
^ -1 |
|
670 |
! |
|
671 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
672 |
literalArrayEncoding |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
673 |
"encode myself as an array literal, from which a copy of the receiver |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
674 |
can be reconstructed with #decodeAsLiteralArray." |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
675 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
676 |
^ self |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
677 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
678 |
"Created: / 27.10.1997 / 14:40:37 / cg" |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
679 |
! |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
680 |
|
699 | 681 |
to:aMagnitude |
682 |
"Return an Interval over the characters from the receiver to <aMagnitude>. |
|
683 |
Wrap <aMagnitude> if it is not a legal Character value. (JS)" |
|
684 |
||
685 |
^ Interval from:self to:(aMagnitude \\ 256) |
|
686 |
! ! |
|
687 |
||
688 |
!Character methodsFor:'copying'! |
|
689 |
||
690 |
copy |
|
691 |
"return a copy of myself |
|
692 |
reimplemented since characters are unique" |
|
693 |
||
694 |
^ self |
|
695 |
! |
|
696 |
||
2214 | 697 |
copyUpToLast: char |
698 |
||
699 |
^self |
|
700 |
! |
|
701 |
||
699 | 702 |
deepCopy |
703 |
"return a deep copy of myself |
|
704 |
reimplemented since characters are unique" |
|
705 |
||
706 |
^ self |
|
707 |
! |
|
708 |
||
709 |
deepCopyUsing:aDictionary |
|
710 |
"return a deep copy of myself |
|
711 |
reimplemented since characters are unique" |
|
712 |
||
713 |
^ self |
|
714 |
! |
|
715 |
||
716 |
shallowCopy |
|
717 |
"return a shallow copy of myself |
|
718 |
reimplemented since characters are unique" |
|
719 |
||
720 |
^ self |
|
721 |
! |
|
722 |
||
723 |
simpleDeepCopy |
|
724 |
"return a deep copy of myself |
|
725 |
reimplemented since characters are unique" |
|
726 |
||
727 |
^ self |
|
728 |
! ! |
|
729 |
||
730 |
!Character methodsFor:'enumerating'! |
|
731 |
||
732 |
to:stopCharacter do:aBlock |
|
733 |
"evaluate aBlock for each character in self .. stopCharacter. |
|
734 |
This is somewhat stupid, since it depends on the ascii encoding |
|
735 |
(370-users watch out :-)" |
|
736 |
||
737 |
|runChar| |
|
738 |
||
739 |
runChar := self. |
|
740 |
[runChar <= stopCharacter] whileTrue:[ |
|
741 |
aBlock value:runChar. |
|
742 |
runChar := runChar + 1 |
|
743 |
] |
|
744 |
||
745 |
" |
|
746 |
($a to:$z) do:[:char | char printNL] |
|
747 |
$a to:$z do:[:char | char printNL]. |
|
748 |
" |
|
749 |
! ! |
|
750 |
||
751 |
!Character methodsFor:'national testing'! |
|
752 |
||
753 |
isNationalAlphaNumeric |
|
2214 | 754 |
"return true, if the receiver is a letter or digit in the |
699 | 755 |
current language (Language variable)" |
756 |
||
757 |
"stupid - should be configurable from a table ... |
|
758 |
... good thing is, that iso8859 puts all national |
|
2214 | 759 |
characters above 16rC0" |
699 | 760 |
|
761 |
self isLetterOrDigit ifTrue:[^ true]. |
|
2214 | 762 |
^ self isNationalLetter |
763 |
||
764 |
"Modified: 21.1.1997 / 11:10:54 / cg" |
|
699 | 765 |
! |
766 |
||
767 |
isNationalLetter |
|
768 |
"return true, if the receiver is a letter in the |
|
769 |
current language (Language variable)" |
|
770 |
||
771 |
"stupid - should be configurable from a table ... |
|
772 |
... good thing is, that iso8859 puts all national |
|
2214 | 773 |
characters above 16rC0" |
774 |
||
699 | 775 |
self isLetter ifTrue:[^ true]. |
2214 | 776 |
(asciivalue between:16rC0 and:16rD6) ifTrue:[^ true]. |
777 |
(asciivalue between:16rD8 and:16rF6) ifTrue:[^ true]. |
|
778 |
(asciivalue between:16rF8 and:16rFF) ifTrue:[^ true]. |
|
779 |
^ false. |
|
780 |
||
781 |
"Modified: 21.1.1997 / 11:13:02 / cg" |
|
699 | 782 |
! ! |
783 |
||
784 |
!Character methodsFor:'printing & storing'! |
|
785 |
||
786 |
displayString |
|
787 |
"return a string used when the receiver is to be displayed |
|
788 |
in an inspector kind-of-thing" |
|
789 |
||
2908 | 790 |
^ (self storeString , ' "16r' , (asciivalue printStringRadix:16) , '"') |
699 | 791 |
! |
792 |
||
793 |
isLiteral |
|
794 |
"return true, if the receiver can be used as a literal |
|
795 |
(i.e. can be used in constant arrays)" |
|
796 |
||
797 |
^ true |
|
798 |
! |
|
799 |
||
800 |
||
801 |
"print myself on stdout" |
|
802 |
||
803 |
%{ /* NOCONTEXT */ |
|
804 |
||
1133 | 805 |
putchar(__intVal(__INST(asciivalue))); |
699 | 806 |
%} |
807 |
! |
|
808 |
||
809 |
printOn:aStream |
|
810 |
"print myself on aStream" |
|
811 |
||
812 |
aStream nextPut:self |
|
813 |
! |
|
814 |
||
815 |
printString |
|
816 |
"return a string to print me" |
|
817 |
||
818 |
^ self asString |
|
819 |
! |
|
820 |
||
2214 | 821 |
reconstructOn:aStream |
822 |
aStream nextPut:$$; nextPut:self |
|
823 |
||
824 |
"Created: 6.2.1996 / 09:46:12 / stefan" |
|
825 |
"Modified: 6.2.1996 / 10:57:35 / stefan" |
|
826 |
! |
|
827 |
||
699 | 828 |
storeOn:aStream |
829 |
"store myself on aStream" |
|
830 |
||
831 |
|special| |
|
832 |
||
833 |
(asciivalue between:33 and:127) ifFalse:[ |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
834 |
(self == Character space) ifTrue:[ |
1007 | 835 |
special := 'space' |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
836 |
] ifFalse:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
837 |
(self == Character cr) ifTrue:[ |
1007 | 838 |
special := 'cr'. |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
839 |
] ifFalse:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
840 |
(self == Character tab) ifTrue:[ |
1007 | 841 |
special := 'tab'. |
842 |
] ifFalse:[ |
|
843 |
(self == Character esc) ifTrue:[ |
|
844 |
special := 'esc'. |
|
845 |
] |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
846 |
] |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
847 |
] |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
848 |
]. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
849 |
special notNil ifTrue:[ |
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
850 |
aStream nextPutAll:'(Character '; nextPutAll:special; nextPut:$). |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
851 |
^ self |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
852 |
]. |
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
853 |
aStream nextPutAll:'(Character value:16r'. |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
854 |
asciivalue printOn:aStream base:16. |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
855 |
aStream nextPut:$) |
699 | 856 |
] ifTrue:[ |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
857 |
aStream nextPut:$$; nextPut:self |
699 | 858 |
] |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
859 |
|
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
860 |
"Modified: / 23.2.1996 / 23:27:32 / cg" |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
861 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
699 | 862 |
! ! |
863 |
||
864 |
!Character methodsFor:'private accessing'! |
|
865 |
||
866 |
setAsciiValue:anInteger |
|
867 |
"very private - set the ascii value. |
|
868 |
- use this only for characters with codes > 16rFF. |
|
869 |
DANGER alert: funny things happen, if this is applied to |
|
870 |
one of the fixed-characters 0..255." |
|
871 |
||
872 |
asciivalue := anInteger |
|
873 |
! ! |
|
874 |
||
1 | 875 |
!Character methodsFor:'testing'! |
876 |
||
699 | 877 |
isAlphaNumeric |
878 |
"return true, if I am a letter or a digit |
|
879 |
- same as isAlphaNumeric for compatibility reasons." |
|
880 |
||
881 |
^ self isLetterOrDigit |
|
882 |
! |
|
883 |
||
54 | 884 |
isCharacter |
885 |
"return true, if the receiver is some kind of character" |
|
886 |
||
887 |
^ true |
|
888 |
! |
|
889 |
||
3667 | 890 |
isControlCharacter |
891 |
"return true if I am a control character (i.e. ascii value < 32)" |
|
892 |
||
893 |
%{ /* NOCONTEXT */ |
|
894 |
#ifdef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
895 |
not yet implemented - fails when compiled |
|
896 |
#else |
|
897 |
REGISTER int val; |
|
898 |
||
899 |
val = __intVal(__INST(asciivalue)); |
|
3881 | 900 |
if (val < ' ') { |
3667 | 901 |
RETURN ( true ); |
902 |
} |
|
903 |
#endif |
|
904 |
%}. |
|
905 |
^ false |
|
906 |
||
907 |
" |
|
908 |
(Character value:1) isControlCharacter |
|
909 |
$a isControlCharacter |
|
910 |
" |
|
911 |
! |
|
912 |
||
1 | 913 |
isDigit |
914 |
"return true, if I am a digit (i.e. $0 .. $9)" |
|
915 |
||
916 |
^ asciivalue between:($0 asciiValue) and:($9 asciiValue) |
|
917 |
! |
|
918 |
||
919 |
isDigitRadix:r |
|
920 |
"return true, if I am a digit of a base r number" |
|
921 |
||
922 |
(asciivalue < $0 asciiValue) ifTrue:[^ false]. |
|
923 |
(r > 10) ifTrue:[ |
|
4037 | 924 |
(asciivalue between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[ |
925 |
^ true |
|
926 |
]. |
|
927 |
((asciivalue - $a asciiValue) between:0 and:(r - 11)) ifTrue:[ |
|
928 |
^ true |
|
929 |
]. |
|
930 |
^ (asciivalue - $A asciiValue) between:0 and:(r - 11) |
|
1 | 931 |
]. |
932 |
(asciivalue - $0 asciiValue) < r ifTrue:[^ true]. |
|
933 |
^ false |
|
934 |
! |
|
935 |
||
699 | 936 |
isEndOfLineCharacter |
937 |
"return true if I am a line delimitting character" |
|
1 | 938 |
|
939 |
%{ /* NOCONTEXT */ |
|
940 |
||
941 |
REGISTER int val; |
|
942 |
||
1133 | 943 |
val = __intVal(__INST(asciivalue)); |
699 | 944 |
if ((val == '\n') |
945 |
|| (val == '\r') |
|
946 |
|| (val == '\f')) { |
|
947 |
RETURN ( true ); |
|
54 | 948 |
} |
1 | 949 |
%} |
699 | 950 |
. |
951 |
^ false |
|
1 | 952 |
! |
953 |
||
954 |
isLetter |
|
54 | 955 |
"return true, if I am a letter |
760
7eeb5f12e7fe
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
956 |
- use isNationalLetter, if you are interested in those." |
1 | 957 |
|
958 |
%{ /*NOCONTEXT */ |
|
959 |
||
960 |
REGISTER int val; |
|
961 |
||
1133 | 962 |
val = __intVal(__INST(asciivalue)); |
1 | 963 |
RETURN ( (((val >= 'a') && (val <= 'z')) || |
154 | 964 |
((val >= 'A') && (val <= 'Z'))) ? true : false ); |
1 | 965 |
%} |
966 |
! |
|
967 |
||
154 | 968 |
isLetterOrDigit |
54 | 969 |
"return true, if I am a letter or a digit |
760
7eeb5f12e7fe
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
700
diff
changeset
|
970 |
- use isNationalAlphaNumeric, if you are interested in those." |
1 | 971 |
|
972 |
%{ /* NOCONTEXT */ |
|
973 |
||
974 |
REGISTER int val; |
|
975 |
||
1133 | 976 |
val = __intVal(__INST(asciivalue)); |
1 | 977 |
if ((val >= 'a') && (val <= 'z')) { |
154 | 978 |
RETURN ( true ); |
1 | 979 |
} |
980 |
if ((val >= 'A') && (val <= 'Z')) { |
|
154 | 981 |
RETURN ( true ); |
1 | 982 |
} |
983 |
if ((val >= '0') && (val <= '9')) { |
|
154 | 984 |
RETURN ( true ); |
1 | 985 |
} |
986 |
RETURN ( false ); |
|
987 |
%} |
|
988 |
! |
|
989 |
||
699 | 990 |
isLowercase |
991 |
"return true, if I am a lower-case letter" |
|
992 |
||
993 |
%{ /* NOCONTEXT */ |
|
994 |
||
995 |
REGISTER int val; |
|
154 | 996 |
|
1133 | 997 |
val = __intVal(__INST(asciivalue)); |
699 | 998 |
#ifndef OLD |
999 |
/* iso8859 puts national lower case characters at e0 .. ff */ |
|
1000 |
if ((val >= 0xE0) && (val <= 0xFF)) { |
|
1001 |
RETURN(true); |
|
1002 |
} |
|
1003 |
#endif |
|
1004 |
RETURN ( ((val >= 'a') && (val <= 'z')) ? true : false ); |
|
1005 |
%} |
|
154 | 1006 |
! |
1007 |
||
699 | 1008 |
isPrintable |
1009 |
"return true, if the receiver is a useful printable character |
|
1010 |
(see fileBrowsers showFile:-method on how it can be used)" |
|
1 | 1011 |
|
699 | 1012 |
(asciivalue between:32 and:127) ifTrue:[^ true]. |
1013 |
asciivalue == 13 ifTrue:[^ true]. |
|
1014 |
asciivalue == 9 ifTrue:[^ true]. |
|
1015 |
asciivalue == 10 ifTrue:[^ true]. |
|
2840 | 1016 |
|
1017 |
(asciivalue between:16rA0 and:16rBF) ifTrue:[^ true]. "/ ISO8859 |
|
699 | 1018 |
^ self isNationalLetter |
2840 | 1019 |
|
1020 |
"Modified: 7.8.1997 / 17:05:24 / cg" |
|
1 | 1021 |
! |
1022 |
||
1023 |
isSeparator |
|
1024 |
"return true if I am a space, cr, tab, nl, or newPage" |
|
1025 |
||
1026 |
%{ /* NOCONTEXT */ |
|
1027 |
||
1028 |
REGISTER int val; |
|
1029 |
||
1133 | 1030 |
val = __intVal(__INST(asciivalue)); |
328 | 1031 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
1032 |
if (val <= ' ') |
|
1033 |
#endif |
|
154 | 1034 |
if ((val == ' ') |
1035 |
|| (val == '\n') |
|
1036 |
|| (val == '\t') |
|
1037 |
|| (val == '\r') |
|
1038 |
|| (val == '\f')) { |
|
1039 |
RETURN ( true ); |
|
1040 |
} |
|
1 | 1041 |
%} |
1042 |
. |
|
1043 |
^ false |
|
1044 |
! |
|
1045 |
||
699 | 1046 |
isUppercase |
1047 |
"return true, if I am an upper-case letter" |
|
1 | 1048 |
|
1049 |
%{ /* NOCONTEXT */ |
|
1050 |
||
1051 |
REGISTER int val; |
|
1052 |
||
1133 | 1053 |
val = __intVal(__INST(asciivalue)); |
699 | 1054 |
#ifndef OLD |
1055 |
/* iso8859 puts national upper case characters at c0 .. df */ |
|
1056 |
if ((val >= 0xC0) && (val <= 0xDF)) { |
|
1057 |
RETURN(true); |
|
314 | 1058 |
} |
699 | 1059 |
#endif |
1060 |
RETURN ( ((val >= 'A') && (val <= 'Z')) ? true : false ); |
|
1 | 1061 |
%} |
1062 |
! |
|
1063 |
||
699 | 1064 |
isVowel |
1065 |
"return true, if I am a vowel (lower- or uppercase)" |
|
333 | 1066 |
|
699 | 1067 |
(self == $a) ifTrue:[^ true]. |
1068 |
(self == $e) ifTrue:[^ true]. |
|
1069 |
(self == $i) ifTrue:[^ true]. |
|
1070 |
(self == $o) ifTrue:[^ true]. |
|
1071 |
(self == $u) ifTrue:[^ true]. |
|
1072 |
(self == $A) ifTrue:[^ true]. |
|
1073 |
(self == $E) ifTrue:[^ true]. |
|
1074 |
(self == $I) ifTrue:[^ true]. |
|
1075 |
(self == $O) ifTrue:[^ true]. |
|
1076 |
(self == $U) ifTrue:[^ true]. |
|
1077 |
^ false |
|
1 | 1078 |
! ! |
699 | 1079 |
|
2124 | 1080 |
!Character class methodsFor:'documentation'! |
699 | 1081 |
|
1082 |
version |
|
4340
523ef8410fad
added #linefeed - squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
4337
diff
changeset
|
1083 |
^ '$Header: /cvs/stx/stx/libbasic/Character.st,v 1.53 1999-07-06 23:59:20 cg Exp $' |
699 | 1084 |
! ! |