author | Claus Gittinger <cg@exept.de> |
Tue, 29 Dec 1998 17:56:57 +0100 | |
changeset 3950 | f9c4485a91d1 |
parent 3881 | e8fd1f890897 |
child 4037 | 1715c72ce46f |
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 |
|
699 | 222 |
maxValue |
223 |
"return the maximum asciiValue a character can have" |
|
224 |
||
225 |
^ 16rFFFF |
|
226 |
! |
|
227 |
||
228 |
newPage |
|
229 |
"return the form-feed character" |
|
230 |
||
231 |
^ Character value:12 |
|
232 |
! |
|
233 |
||
234 |
nl |
|
235 |
"return the newline character" |
|
68 | 236 |
|
699 | 237 |
^ Character value:10 |
238 |
! |
|
239 |
||
240 |
quote |
|
241 |
"return the single-quote character" |
|
242 |
||
243 |
^ Character value:39 |
|
244 |
! |
|
245 |
||
246 |
return |
|
247 |
"return the return character. |
|
248 |
In ST/X, this is different from cr - for Unix reasons." |
|
249 |
||
250 |
^ Character value:13 |
|
251 |
! |
|
252 |
||
253 |
space |
|
254 |
"return the blank character" |
|
255 |
||
256 |
^ Character value:32 |
|
257 |
! |
|
258 |
||
259 |
tab |
|
260 |
"return the tabulator character" |
|
261 |
||
262 |
^ Character value:9 |
|
1 | 263 |
! ! |
264 |
||
2124 | 265 |
!Character class methodsFor:'primitive input'! |
1 | 266 |
|
267 |
fromUser |
|
357 | 268 |
"return a character from the keyboard (C's standard input stream) |
1 | 269 |
- this should only be used for emergency evaluators and the like." |
270 |
||
271 |
%{ /* NOCONTEXT */ |
|
272 |
int c; |
|
273 |
||
274 |
c = getchar(); |
|
275 |
if (c < 0) { |
|
154 | 276 |
RETURN (nil); |
1 | 277 |
} |
1133 | 278 |
RETURN ( __MKCHARACTER(c & 0xFF) ); |
1 | 279 |
%} |
280 |
! ! |
|
281 |
||
2124 | 282 |
!Character class methodsFor:'queries'! |
3 | 283 |
|
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
284 |
hasImmediateInstances |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
285 |
"return true if this class has immediate instances. |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
286 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
287 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
288 |
^ self == Character |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
289 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
290 |
"Created: 3.6.1997 / 12:01:52 / cg" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
291 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2561
diff
changeset
|
292 |
|
3 | 293 |
isBuiltInClass |
1271 | 294 |
"return true if this class is known by the run-time-system. |
295 |
Here, true is returned for myself, false for subclasses." |
|
3 | 296 |
|
297 |
^ self == Character |
|
1271 | 298 |
|
299 |
"Modified: 23.4.1996 / 15:56:39 / cg" |
|
3 | 300 |
! ! |
301 |
||
1 | 302 |
!Character methodsFor:'accessing'! |
303 |
||
304 |
asciiValue |
|
54 | 305 |
"return the asciivalue of myself. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
306 |
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
|
307 |
limited to 8bit characters. |
54 | 308 |
PP has removed this methhod with 4.1 and providing |
309 |
asInteger instead." |
|
1 | 310 |
|
311 |
^asciivalue |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
312 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
313 |
"Modified: 27.6.1996 / 12:34:34 / cg" |
1 | 314 |
! |
315 |
||
316 |
instVarAt:index put:anObject |
|
54 | 317 |
"catch instvar access - asciivalue may not be changed" |
1 | 318 |
|
319 |
self error:'Characters may not be modified' |
|
2214 | 320 |
! |
321 |
||
322 |
newDigitValue |
|
323 |
"Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0 otherwise. |
|
324 |
This is used to parse literal numbers of radix 2-36." |
|
325 |
||
326 |
| code value | |
|
327 |
code := self asInteger. |
|
328 |
value := code - $0 asInteger. |
|
329 |
value <= 9 ifTrue: [^value]. |
|
330 |
value := code - $A asInteger. |
|
331 |
(value >= 0 and: [value < 26]) |
|
332 |
ifTrue: [^value + 10]. |
|
333 |
^-1 |
|
1 | 334 |
! ! |
335 |
||
699 | 336 |
!Character methodsFor:'arithmetic'! |
1 | 337 |
|
338 |
+ aMagnitude |
|
339 |
"Return the Character that is <aMagnitude> higher than the receiver. |
|
340 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
341 |
||
2 | 342 |
^ Character value:(asciivalue + aMagnitude asInteger \\ 256) |
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 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
345 |
$A + 5 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
346 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
347 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
348 |
"Modified: 27.6.1996 / 12:34:51 / cg" |
1 | 349 |
! |
350 |
||
351 |
- aMagnitude |
|
352 |
"Return the Character that is <aMagnitude> lower than the receiver. |
|
68 | 353 |
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
|
354 |
claus: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
returned." |
1 | 358 |
|
68 | 359 |
aMagnitude isCharacter ifTrue:[ |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
360 |
^ self asciiValue - aMagnitude asciiValue |
68 | 361 |
]. |
2 | 362 |
^ Character value:(asciivalue - aMagnitude asInteger \\ 256) |
68 | 363 |
|
364 |
" |
|
365 |
$z - $a |
|
366 |
$d - 3 |
|
367 |
" |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
368 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
369 |
"Modified: 27.6.1996 / 12:35:34 / cg" |
1 | 370 |
! |
371 |
||
372 |
// aMagnitude |
|
373 |
"Return the Character who's value is the receiver divided by <aMagnitude>. |
|
374 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
375 |
||
2 | 376 |
^ Character value:(asciivalue // aMagnitude asInteger \\ 256) |
1 | 377 |
! |
378 |
||
379 |
\\ aMagnitude |
|
380 |
"Return the Character who's value is the receiver modulo <aMagnitude>. |
|
381 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
382 |
||
2 | 383 |
^ Character value:(asciivalue \\ aMagnitude asInteger \\ 256) |
1 | 384 |
! ! |
385 |
||
699 | 386 |
!Character methodsFor:'binary storage'! |
387 |
||
388 |
hasSpecialBinaryRepresentation |
|
389 |
"return true, if the receiver has a special binary representation" |
|
390 |
||
391 |
^ true |
|
392 |
! |
|
393 |
||
394 |
storeBinaryOn:stream manager:manager |
|
395 |
"store a binary representation of the receiver on stream; |
|
396 |
redefined, since single-byte characters are stored more compact |
|
397 |
with a special type-code followed by the asciiValue." |
|
398 |
||
399 |
(asciivalue < 256) ifTrue:[ |
|
3072 | 400 |
stream nextPut:manager codeForCharacter; nextPut:asciivalue. |
699 | 401 |
] ifFalse:[ |
3072 | 402 |
stream nextPut:manager codeForTwoByteCharacter. |
403 |
stream nextPutShort:asciivalue MSB:true |
|
699 | 404 |
] |
3072 | 405 |
|
406 |
"Modified: / 2.11.1997 / 14:14:50 / cg" |
|
699 | 407 |
! ! |
408 |
||
409 |
!Character methodsFor:'comparing'! |
|
410 |
||
411 |
< aCharacter |
|
412 |
"return true, if the arguments asciiValue is greater than mine" |
|
413 |
||
414 |
^ (asciivalue < aCharacter asciiValue) |
|
415 |
! |
|
416 |
||
417 |
<= aCharacter |
|
418 |
"return true, if the arguments asciiValue is greater or equal to mine" |
|
419 |
||
420 |
^ (asciivalue <= aCharacter asciiValue) |
|
421 |
! |
|
422 |
||
423 |
= aCharacter |
|
424 |
"return true, if the argument, aCharacter is the same character |
|
425 |
Redefined to take care of 16bit characters." |
|
426 |
||
427 |
self == aCharacter ifTrue:[^ true]. |
|
428 |
aCharacter isCharacter ifFalse:[^ false]. |
|
429 |
^ (asciivalue = aCharacter asciiValue) |
|
430 |
! |
|
431 |
||
432 |
> aCharacter |
|
433 |
"return true, if the arguments asciiValue is less than mine" |
|
434 |
||
435 |
^ (asciivalue > aCharacter asciiValue) |
|
436 |
! |
|
437 |
||
438 |
>= aCharacter |
|
439 |
"return true, if the arguments asciiValue is less or equal to mine" |
|
440 |
||
441 |
^ (asciivalue >= aCharacter asciiValue) |
|
442 |
! |
|
443 |
||
444 |
identityHash |
|
445 |
"return an integer useful for hashing on identity" |
|
446 |
||
447 |
asciivalue <= 255 ifTrue:[ |
|
448 |
^ 4096 + asciivalue |
|
449 |
]. |
|
450 |
^ super identityHash |
|
451 |
! |
|
452 |
||
453 |
sameAs:aCharacter |
|
454 |
"return true, if the argument, aCharacter is the same character, |
|
455 |
ignoring case differences." |
|
456 |
||
457 |
self == aCharacter ifTrue:[^ true]. |
|
458 |
^ self asLowercase = aCharacter asLowercase |
|
459 |
! |
|
460 |
||
461 |
~= aCharacter |
|
462 |
"return true, if the argument, aCharacter is not the same character |
|
463 |
Redefined to take care of 16bit characters." |
|
464 |
||
465 |
self == aCharacter ifTrue:[^ false]. |
|
466 |
aCharacter isCharacter ifFalse:[^ true]. |
|
467 |
^ (asciivalue ~~ aCharacter asciiValue) |
|
468 |
! ! |
|
469 |
||
470 |
!Character methodsFor:'converting'! |
|
471 |
||
472 |
asCharacter |
|
473 |
"usually sent to integers, but redefined here to allow integers |
|
474 |
and characters to be used commonly without a need for a test." |
|
475 |
||
476 |
^ self |
|
477 |
||
478 |
" |
|
479 |
32 asCharacter |
|
480 |
" |
|
481 |
! |
|
482 |
||
483 |
asInteger |
|
484 |
"return an Integer with my ascii-value. |
|
485 |
OWST4.2 compatibility (sigh)" |
|
486 |
||
487 |
^ asciivalue |
|
488 |
! |
|
489 |
||
490 |
asLowercase |
|
491 |
"return a character with same letter as the receiver, |
|
492 |
but lowercase (the receiver if its lowercase or nonLetter)" |
|
493 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
494 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
495 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
496 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
497 |
"/ self isUppercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
498 |
"/ ^ Character value:(asciivalue + 32) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
499 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
500 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
501 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
502 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
503 |
((code >= $A asciiValue) and:[code <= $Z asciiValue]) ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
504 |
^ Character value:(code + ($a asciiValue - $A asciiValue)) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
505 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
506 |
code < 16r00C0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
507 |
code < 16r0100 ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
508 |
code >= 16r00DF ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
509 |
code == 16r00D7 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
510 |
^ Character value:(code + 16r20) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
511 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
512 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
513 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
514 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
515 |
|
2124 | 516 |
'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
|
517 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
518 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
519 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
520 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
521 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
522 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
523 |
|
2124 | 524 |
"Modified: 10.1.1997 / 15:35:44 / cg" |
699 | 525 |
! |
526 |
||
527 |
asString |
|
528 |
"return a string of len 1 with myself as contents" |
|
529 |
||
530 |
%{ /* NOCONTEXT */ |
|
531 |
char buffer[2]; |
|
532 |
OBJ s; |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
533 |
unsigned val; |
699 | 534 |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
535 |
val = __intVal(_characterVal(self)); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
536 |
if (val <= 0xFF) { |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
537 |
buffer[0] = (char) val; |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
538 |
buffer[1] = '\0'; |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
539 |
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
|
540 |
if (s != nil) { |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
541 |
RETURN (s); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
542 |
} |
699 | 543 |
} |
544 |
%}. |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
545 |
asciivalue > 255 ifTrue:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
546 |
^ (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
|
547 |
]. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
548 |
|
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
549 |
"/ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
550 |
"/ ^ (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
|
551 |
"/ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
552 |
|
699 | 553 |
" |
554 |
memory allocation (for the new string) failed. |
|
555 |
When we arrive here, there was no memory, even after a garbage collect. |
|
556 |
This means, that the VM wanted to get some more memory from the |
|
557 |
OS, which was not kind enough to give it. |
|
558 |
Bad luck - you should increase the swap space on your machine. |
|
559 |
" |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
560 |
|
699 | 561 |
^ ObjectMemory allocationFailureSignal raise. |
562 |
! |
|
563 |
||
564 |
asSymbol |
|
565 |
"return a unique symbol which prints like I print" |
|
566 |
||
567 |
^ Symbol internCharacter:self |
|
568 |
! |
|
569 |
||
570 |
asUppercase |
|
571 |
"return a character with same letter as the receiver, |
|
572 |
but uppercase (the receiver if its uppercase or nonLetter)" |
|
573 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
574 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
575 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
576 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
577 |
"/ self isLowercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
578 |
"/ ^ Character value:(asciivalue - 32) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
579 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
580 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
581 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
582 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
583 |
((code >= $a asciiValue) and:[code <= $z asciiValue]) ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
584 |
^ Character value:(code + ($A asciiValue - $a asciiValue)) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
585 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
586 |
code < 16r00E0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
587 |
code < 16r0100 ifTrue:[ |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
588 |
code == 16r00F7 ifTrue:[^ self]. "/ division |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
589 |
"/ 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
|
590 |
code == 16r00FF ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
591 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
592 |
^ Character value:(code - 16r20) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
593 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
594 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
595 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
596 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
597 |
|
2124 | 598 |
'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
|
599 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
600 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
601 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
602 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
603 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
604 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
605 |
|
2124 | 606 |
"Modified: 10.1.1997 / 15:35:51 / cg" |
699 | 607 |
! |
608 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
609 |
decodeAsLiteralArray |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
610 |
"given a literalEncoding in the receiver, |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
611 |
create & return the corresponding object. |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
612 |
The inverse operation to #literalArrayEncoding." |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
613 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
614 |
^ self |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
615 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
616 |
"Created: / 27.10.1997 / 14:40:16 / cg" |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
617 |
! |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
618 |
|
699 | 619 |
digitValue |
620 |
"return my digitValue for any base" |
|
621 |
||
622 |
|ascii "{ Class: SmallInteger }" | |
|
623 |
||
624 |
ascii := asciivalue. |
|
625 |
(ascii between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[ |
|
626 |
^ ascii - $0 asciiValue |
|
627 |
]. |
|
628 |
(ascii between:($a asciiValue) and:($z asciiValue)) ifTrue:[ |
|
629 |
^ ascii + (10 - $a asciiValue) |
|
630 |
]. |
|
631 |
(ascii between:($A asciiValue) and:($Z asciiValue)) ifTrue:[ |
|
632 |
^ ascii + (10 - $A asciiValue) |
|
633 |
]. |
|
634 |
||
635 |
"remove error below for X3J20 conformance ... " |
|
636 |
self error:'bad character'. |
|
637 |
" " |
|
638 |
^ -1 |
|
639 |
! |
|
640 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
641 |
literalArrayEncoding |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
642 |
"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
|
643 |
can be reconstructed with #decodeAsLiteralArray." |
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:37 / 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 |
to:aMagnitude |
651 |
"Return an Interval over the characters from the receiver to <aMagnitude>. |
|
652 |
Wrap <aMagnitude> if it is not a legal Character value. (JS)" |
|
653 |
||
654 |
^ Interval from:self to:(aMagnitude \\ 256) |
|
655 |
! ! |
|
656 |
||
657 |
!Character methodsFor:'copying'! |
|
658 |
||
659 |
copy |
|
660 |
"return a copy of myself |
|
661 |
reimplemented since characters are unique" |
|
662 |
||
663 |
^ self |
|
664 |
! |
|
665 |
||
2214 | 666 |
copyUpToLast: char |
667 |
||
668 |
^self |
|
669 |
! |
|
670 |
||
699 | 671 |
deepCopy |
672 |
"return a deep copy of myself |
|
673 |
reimplemented since characters are unique" |
|
674 |
||
675 |
^ self |
|
676 |
! |
|
677 |
||
678 |
deepCopyUsing:aDictionary |
|
679 |
"return a deep copy of myself |
|
680 |
reimplemented since characters are unique" |
|
681 |
||
682 |
^ self |
|
683 |
! |
|
684 |
||
685 |
shallowCopy |
|
686 |
"return a shallow copy of myself |
|
687 |
reimplemented since characters are unique" |
|
688 |
||
689 |
^ self |
|
690 |
! |
|
691 |
||
692 |
simpleDeepCopy |
|
693 |
"return a deep copy of myself |
|
694 |
reimplemented since characters are unique" |
|
695 |
||
696 |
^ self |
|
697 |
! ! |
|
698 |
||
699 |
!Character methodsFor:'enumerating'! |
|
700 |
||
701 |
to:stopCharacter do:aBlock |
|
702 |
"evaluate aBlock for each character in self .. stopCharacter. |
|
703 |
This is somewhat stupid, since it depends on the ascii encoding |
|
704 |
(370-users watch out :-)" |
|
705 |
||
706 |
|runChar| |
|
707 |
||
708 |
runChar := self. |
|
709 |
[runChar <= stopCharacter] whileTrue:[ |
|
710 |
aBlock value:runChar. |
|
711 |
runChar := runChar + 1 |
|
712 |
] |
|
713 |
||
714 |
" |
|
715 |
($a to:$z) do:[:char | char printNL] |
|
716 |
$a to:$z do:[:char | char printNL]. |
|
717 |
" |
|
718 |
! ! |
|
719 |
||
720 |
!Character methodsFor:'national testing'! |
|
721 |
||
722 |
isNationalAlphaNumeric |
|
2214 | 723 |
"return true, if the receiver is a letter or digit in the |
699 | 724 |
current language (Language variable)" |
725 |
||
726 |
"stupid - should be configurable from a table ... |
|
727 |
... good thing is, that iso8859 puts all national |
|
2214 | 728 |
characters above 16rC0" |
699 | 729 |
|
730 |
self isLetterOrDigit ifTrue:[^ true]. |
|
2214 | 731 |
^ self isNationalLetter |
732 |
||
733 |
"Modified: 21.1.1997 / 11:10:54 / cg" |
|
699 | 734 |
! |
735 |
||
736 |
isNationalLetter |
|
737 |
"return true, if the receiver is a letter in the |
|
738 |
current language (Language variable)" |
|
739 |
||
740 |
"stupid - should be configurable from a table ... |
|
741 |
... good thing is, that iso8859 puts all national |
|
2214 | 742 |
characters above 16rC0" |
743 |
||
699 | 744 |
self isLetter ifTrue:[^ true]. |
2214 | 745 |
(asciivalue between:16rC0 and:16rD6) ifTrue:[^ true]. |
746 |
(asciivalue between:16rD8 and:16rF6) ifTrue:[^ true]. |
|
747 |
(asciivalue between:16rF8 and:16rFF) ifTrue:[^ true]. |
|
748 |
^ false. |
|
749 |
||
750 |
"Modified: 21.1.1997 / 11:13:02 / cg" |
|
699 | 751 |
! ! |
752 |
||
753 |
!Character methodsFor:'printing & storing'! |
|
754 |
||
755 |
displayString |
|
756 |
"return a string used when the receiver is to be displayed |
|
757 |
in an inspector kind-of-thing" |
|
758 |
||
2908 | 759 |
^ (self storeString , ' "16r' , (asciivalue printStringRadix:16) , '"') |
699 | 760 |
! |
761 |
||
762 |
isLiteral |
|
763 |
"return true, if the receiver can be used as a literal |
|
764 |
(i.e. can be used in constant arrays)" |
|
765 |
||
766 |
^ true |
|
767 |
! |
|
768 |
||
769 |
||
770 |
"print myself on stdout" |
|
771 |
||
772 |
%{ /* NOCONTEXT */ |
|
773 |
||
1133 | 774 |
putchar(__intVal(__INST(asciivalue))); |
699 | 775 |
%} |
776 |
! |
|
777 |
||
778 |
printOn:aStream |
|
779 |
"print myself on aStream" |
|
780 |
||
781 |
aStream nextPut:self |
|
782 |
! |
|
783 |
||
784 |
printString |
|
785 |
"return a string to print me" |
|
786 |
||
787 |
^ self asString |
|
788 |
! |
|
789 |
||
2214 | 790 |
reconstructOn:aStream |
791 |
aStream nextPut:$$; nextPut:self |
|
792 |
||
793 |
"Created: 6.2.1996 / 09:46:12 / stefan" |
|
794 |
"Modified: 6.2.1996 / 10:57:35 / stefan" |
|
795 |
! |
|
796 |
||
699 | 797 |
storeOn:aStream |
798 |
"store myself on aStream" |
|
799 |
||
800 |
|special| |
|
801 |
||
802 |
(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
|
803 |
(self == Character space) ifTrue:[ |
1007 | 804 |
special := 'space' |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
805 |
] ifFalse:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
806 |
(self == Character cr) ifTrue:[ |
1007 | 807 |
special := 'cr'. |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
808 |
] ifFalse:[ |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
809 |
(self == Character tab) ifTrue:[ |
1007 | 810 |
special := 'tab'. |
811 |
] ifFalse:[ |
|
812 |
(self == Character esc) ifTrue:[ |
|
813 |
special := 'esc'. |
|
814 |
] |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
815 |
] |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
816 |
] |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
817 |
]. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
818 |
special notNil ifTrue:[ |
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
819 |
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
|
820 |
^ self |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
821 |
]. |
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
822 |
aStream nextPutAll:'(Character value:16r'. |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
823 |
asciivalue printOn:aStream base:16. |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
824 |
aStream nextPut:$) |
699 | 825 |
] ifTrue:[ |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
826 |
aStream nextPut:$$; nextPut:self |
699 | 827 |
] |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
828 |
|
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
829 |
"Modified: / 23.2.1996 / 23:27:32 / cg" |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
830 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
699 | 831 |
! ! |
832 |
||
833 |
!Character methodsFor:'private accessing'! |
|
834 |
||
835 |
setAsciiValue:anInteger |
|
836 |
"very private - set the ascii value. |
|
837 |
- use this only for characters with codes > 16rFF. |
|
838 |
DANGER alert: funny things happen, if this is applied to |
|
839 |
one of the fixed-characters 0..255." |
|
840 |
||
841 |
asciivalue := anInteger |
|
842 |
! ! |
|
843 |
||
1 | 844 |
!Character methodsFor:'testing'! |
845 |
||
699 | 846 |
isAlphaNumeric |
847 |
"return true, if I am a letter or a digit |
|
848 |
- same as isAlphaNumeric for compatibility reasons." |
|
849 |
||
850 |
^ self isLetterOrDigit |
|
851 |
! |
|
852 |
||
54 | 853 |
isCharacter |
854 |
"return true, if the receiver is some kind of character" |
|
855 |
||
856 |
^ true |
|
857 |
! |
|
858 |
||
3667 | 859 |
isControlCharacter |
860 |
"return true if I am a control character (i.e. ascii value < 32)" |
|
861 |
||
862 |
%{ /* NOCONTEXT */ |
|
863 |
#ifdef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
864 |
not yet implemented - fails when compiled |
|
865 |
#else |
|
866 |
REGISTER int val; |
|
867 |
||
868 |
val = __intVal(__INST(asciivalue)); |
|
3881 | 869 |
if (val < ' ') { |
3667 | 870 |
RETURN ( true ); |
871 |
} |
|
872 |
#endif |
|
873 |
%}. |
|
874 |
^ false |
|
875 |
||
876 |
" |
|
877 |
(Character value:1) isControlCharacter |
|
878 |
$a isControlCharacter |
|
879 |
" |
|
880 |
! |
|
881 |
||
1 | 882 |
isDigit |
883 |
"return true, if I am a digit (i.e. $0 .. $9)" |
|
884 |
||
885 |
^ asciivalue between:($0 asciiValue) and:($9 asciiValue) |
|
886 |
! |
|
887 |
||
888 |
isDigitRadix:r |
|
889 |
"return true, if I am a digit of a base r number" |
|
890 |
||
891 |
(asciivalue < $0 asciiValue) ifTrue:[^ false]. |
|
892 |
(r > 10) ifTrue:[ |
|
154 | 893 |
(asciivalue between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[ |
894 |
^ true |
|
895 |
]. |
|
896 |
((asciivalue - $a asciiValue) between:0 and:(r - 10)) ifTrue:[ |
|
897 |
^ true |
|
898 |
]. |
|
899 |
^ (asciivalue - $A asciiValue) between:0 and:(r - 10) |
|
1 | 900 |
]. |
901 |
(asciivalue - $0 asciiValue) < r ifTrue:[^ true]. |
|
902 |
^ false |
|
903 |
! |
|
904 |
||
699 | 905 |
isEndOfLineCharacter |
906 |
"return true if I am a line delimitting character" |
|
1 | 907 |
|
908 |
%{ /* NOCONTEXT */ |
|
909 |
||
910 |
REGISTER int val; |
|
911 |
||
1133 | 912 |
val = __intVal(__INST(asciivalue)); |
699 | 913 |
if ((val == '\n') |
914 |
|| (val == '\r') |
|
915 |
|| (val == '\f')) { |
|
916 |
RETURN ( true ); |
|
54 | 917 |
} |
1 | 918 |
%} |
699 | 919 |
. |
920 |
^ false |
|
1 | 921 |
! |
922 |
||
923 |
isLetter |
|
54 | 924 |
"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
|
925 |
- use isNationalLetter, if you are interested in those." |
1 | 926 |
|
927 |
%{ /*NOCONTEXT */ |
|
928 |
||
929 |
REGISTER int val; |
|
930 |
||
1133 | 931 |
val = __intVal(__INST(asciivalue)); |
1 | 932 |
RETURN ( (((val >= 'a') && (val <= 'z')) || |
154 | 933 |
((val >= 'A') && (val <= 'Z'))) ? true : false ); |
1 | 934 |
%} |
935 |
! |
|
936 |
||
154 | 937 |
isLetterOrDigit |
54 | 938 |
"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
|
939 |
- use isNationalAlphaNumeric, if you are interested in those." |
1 | 940 |
|
941 |
%{ /* NOCONTEXT */ |
|
942 |
||
943 |
REGISTER int val; |
|
944 |
||
1133 | 945 |
val = __intVal(__INST(asciivalue)); |
1 | 946 |
if ((val >= 'a') && (val <= 'z')) { |
154 | 947 |
RETURN ( true ); |
1 | 948 |
} |
949 |
if ((val >= 'A') && (val <= 'Z')) { |
|
154 | 950 |
RETURN ( true ); |
1 | 951 |
} |
952 |
if ((val >= '0') && (val <= '9')) { |
|
154 | 953 |
RETURN ( true ); |
1 | 954 |
} |
955 |
RETURN ( false ); |
|
956 |
%} |
|
957 |
! |
|
958 |
||
699 | 959 |
isLowercase |
960 |
"return true, if I am a lower-case letter" |
|
961 |
||
962 |
%{ /* NOCONTEXT */ |
|
963 |
||
964 |
REGISTER int val; |
|
154 | 965 |
|
1133 | 966 |
val = __intVal(__INST(asciivalue)); |
699 | 967 |
#ifndef OLD |
968 |
/* iso8859 puts national lower case characters at e0 .. ff */ |
|
969 |
if ((val >= 0xE0) && (val <= 0xFF)) { |
|
970 |
RETURN(true); |
|
971 |
} |
|
972 |
#endif |
|
973 |
RETURN ( ((val >= 'a') && (val <= 'z')) ? true : false ); |
|
974 |
%} |
|
154 | 975 |
! |
976 |
||
699 | 977 |
isPrintable |
978 |
"return true, if the receiver is a useful printable character |
|
979 |
(see fileBrowsers showFile:-method on how it can be used)" |
|
1 | 980 |
|
699 | 981 |
(asciivalue between:32 and:127) ifTrue:[^ true]. |
982 |
asciivalue == 13 ifTrue:[^ true]. |
|
983 |
asciivalue == 9 ifTrue:[^ true]. |
|
984 |
asciivalue == 10 ifTrue:[^ true]. |
|
2840 | 985 |
|
986 |
(asciivalue between:16rA0 and:16rBF) ifTrue:[^ true]. "/ ISO8859 |
|
699 | 987 |
^ self isNationalLetter |
2840 | 988 |
|
989 |
"Modified: 7.8.1997 / 17:05:24 / cg" |
|
1 | 990 |
! |
991 |
||
992 |
isSeparator |
|
993 |
"return true if I am a space, cr, tab, nl, or newPage" |
|
994 |
||
995 |
%{ /* NOCONTEXT */ |
|
996 |
||
997 |
REGISTER int val; |
|
998 |
||
1133 | 999 |
val = __intVal(__INST(asciivalue)); |
328 | 1000 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
1001 |
if (val <= ' ') |
|
1002 |
#endif |
|
154 | 1003 |
if ((val == ' ') |
1004 |
|| (val == '\n') |
|
1005 |
|| (val == '\t') |
|
1006 |
|| (val == '\r') |
|
1007 |
|| (val == '\f')) { |
|
1008 |
RETURN ( true ); |
|
1009 |
} |
|
1 | 1010 |
%} |
1011 |
. |
|
1012 |
^ false |
|
1013 |
! |
|
1014 |
||
699 | 1015 |
isUppercase |
1016 |
"return true, if I am an upper-case letter" |
|
1 | 1017 |
|
1018 |
%{ /* NOCONTEXT */ |
|
1019 |
||
1020 |
REGISTER int val; |
|
1021 |
||
1133 | 1022 |
val = __intVal(__INST(asciivalue)); |
699 | 1023 |
#ifndef OLD |
1024 |
/* iso8859 puts national upper case characters at c0 .. df */ |
|
1025 |
if ((val >= 0xC0) && (val <= 0xDF)) { |
|
1026 |
RETURN(true); |
|
314 | 1027 |
} |
699 | 1028 |
#endif |
1029 |
RETURN ( ((val >= 'A') && (val <= 'Z')) ? true : false ); |
|
1 | 1030 |
%} |
1031 |
! |
|
1032 |
||
699 | 1033 |
isVowel |
1034 |
"return true, if I am a vowel (lower- or uppercase)" |
|
333 | 1035 |
|
699 | 1036 |
(self == $a) ifTrue:[^ true]. |
1037 |
(self == $e) ifTrue:[^ true]. |
|
1038 |
(self == $i) ifTrue:[^ true]. |
|
1039 |
(self == $o) ifTrue:[^ true]. |
|
1040 |
(self == $u) ifTrue:[^ true]. |
|
1041 |
(self == $A) ifTrue:[^ true]. |
|
1042 |
(self == $E) ifTrue:[^ true]. |
|
1043 |
(self == $I) ifTrue:[^ true]. |
|
1044 |
(self == $O) ifTrue:[^ true]. |
|
1045 |
(self == $U) ifTrue:[^ true]. |
|
1046 |
^ false |
|
1 | 1047 |
! ! |
699 | 1048 |
|
2124 | 1049 |
!Character class methodsFor:'documentation'! |
699 | 1050 |
|
1051 |
version |
|
3881 | 1052 |
^ '$Header: /cvs/stx/stx/libbasic/Character.st,v 1.50 1998-10-16 11:43:45 cg Exp $' |
699 | 1053 |
! ! |