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
|
|
14 |
instanceVariableNames:'asciivalue'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
|
18 |
!
|
|
19 |
|
|
20 |
Character comment:'
|
5
|
21 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
154
|
22 |
All Rights Reserved
|
92
|
23 |
|
154
|
24 |
$Header: /cvs/stx/stx/libbasic/Character.st,v 1.12 1994-10-10 00:19:58 claus Exp $
|
54
|
25 |
'!
|
|
26 |
|
|
27 |
!Character class methodsFor:'documentation'!
|
|
28 |
|
88
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
154
|
32 |
All Rights Reserved
|
88
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
154
|
45 |
$Header: /cvs/stx/stx/libbasic/Character.st,v 1.12 1994-10-10 00:19:58 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
54
|
49 |
documentation
|
|
50 |
"
|
68
|
51 |
Single byte Characters are unique; this means that for every asciiValue (0..255) there
|
|
52 |
is exactly one instance of Character, which is shared.
|
|
53 |
Other characters (i.e. asciivalue > 255) are not shared.
|
1
|
54 |
|
68
|
55 |
Methods marked as (JS) come from the manchester Character goody
|
|
56 |
(CharacterComparing) by Jan Steinman, which allow Characters to be used as
|
|
57 |
Interval elements (i.e. ($a to:$z) do:[...] ); some of these have been
|
|
58 |
modified a bit.
|
1
|
59 |
|
68
|
60 |
WARNING: characters are known by compiler and runtime system -
|
|
61 |
do not change the instance layout.
|
|
62 |
Also, although you can subclass Character, the compiler creates instances of
|
|
63 |
Character for literals and other classes return Characters hard-wired (i.e.
|
|
64 |
String, Symbol etc.).
|
54
|
65 |
"
|
|
66 |
! !
|
1
|
67 |
|
|
68 |
!Character class methodsFor:'instance creation'!
|
|
69 |
|
|
70 |
basicNew
|
|
71 |
"catch new - Characters cannot be created with new"
|
|
72 |
|
|
73 |
^ self error:'Characters cannot be created with new'
|
|
74 |
!
|
|
75 |
|
|
76 |
value:anInteger
|
|
77 |
"return a character with asciivalue anInteger"
|
|
78 |
|
|
79 |
%{ /* NOCONTEXT */
|
|
80 |
|
54
|
81 |
INT ascii;
|
1
|
82 |
|
|
83 |
if (_isSmallInteger(anInteger)) {
|
154
|
84 |
ascii = _intVal(anInteger);
|
|
85 |
if ((ascii & ~0xFF) == 0 /* (ascii >= 0) && (ascii <= 255) */)
|
|
86 |
RETURN ( _MKCHARACTER(ascii) );
|
1
|
87 |
}
|
|
88 |
%}
|
|
89 |
.
|
|
90 |
(anInteger between:0 and:16rFF) ifTrue:[
|
154
|
91 |
^ CharacterTable at:(anInteger + 1)
|
1
|
92 |
].
|
|
93 |
(anInteger between:16r100 and:16rFFFF) ifTrue:[
|
154
|
94 |
^ super basicNew setAsciiValue:anInteger
|
1
|
95 |
].
|
|
96 |
self error:'invalid ascii code for character'
|
|
97 |
!
|
|
98 |
|
|
99 |
digitValue:anInteger
|
|
100 |
"return a character that corresponds to anInteger.
|
|
101 |
0-9 map to $0-$9, 10-35 map to $A-$Z"
|
|
102 |
|
68
|
103 |
|val "{ Class: SmallInteger }" |
|
|
104 |
|
|
105 |
val := anInteger.
|
|
106 |
(val between:0 and:9) ifTrue:[
|
154
|
107 |
^ Character value:(val + ($0 asciiValue))
|
1
|
108 |
].
|
68
|
109 |
(val between:10 and:35) ifTrue:[
|
154
|
110 |
^ Character value:(val + ($A asciiValue - 10))
|
1
|
111 |
].
|
|
112 |
^self error:'value not in range 0 to 35'
|
|
113 |
! !
|
|
114 |
|
|
115 |
!Character class methodsFor:'primitive input'!
|
|
116 |
|
|
117 |
fromUser
|
|
118 |
"return a character from the keyboard
|
|
119 |
- this should only be used for emergency evaluators and the like."
|
|
120 |
|
|
121 |
%{ /* NOCONTEXT */
|
|
122 |
int c;
|
|
123 |
|
|
124 |
c = getchar();
|
|
125 |
if (c < 0) {
|
154
|
126 |
RETURN (nil);
|
1
|
127 |
}
|
|
128 |
RETURN ( _MKCHARACTER(c & 0xFF) );
|
|
129 |
%}
|
|
130 |
! !
|
|
131 |
|
3
|
132 |
!Character class methodsFor:'queries'!
|
|
133 |
|
|
134 |
isBuiltInClass
|
54
|
135 |
"return true, if this classes instance layout cannot be changed
|
|
136 |
- this class is known by the run-time-system (but not subclasses)"
|
3
|
137 |
|
|
138 |
^ self == Character
|
|
139 |
! !
|
|
140 |
|
1
|
141 |
!Character class methodsFor:'constants'!
|
|
142 |
|
|
143 |
bell
|
|
144 |
"return the bell character"
|
|
145 |
|
|
146 |
^ Character value:7
|
|
147 |
!
|
|
148 |
|
|
149 |
backspace
|
|
150 |
"return the backspace character"
|
|
151 |
|
|
152 |
^ Character value:8
|
|
153 |
!
|
|
154 |
|
|
155 |
nl
|
|
156 |
"return the newline character"
|
|
157 |
|
|
158 |
^ Character value:10
|
|
159 |
!
|
|
160 |
|
|
161 |
lf
|
|
162 |
"return the newline/linefeed character"
|
|
163 |
|
|
164 |
^ Character value:10
|
|
165 |
!
|
|
166 |
|
|
167 |
cr
|
|
168 |
"return the carriage-return character
|
|
169 |
- actually (in unix) this is also a newline"
|
|
170 |
|
|
171 |
^ Character value:10
|
|
172 |
!
|
|
173 |
|
|
174 |
tab
|
|
175 |
"return the tabulator character"
|
|
176 |
|
|
177 |
^ Character value:9
|
|
178 |
!
|
|
179 |
|
|
180 |
newPage
|
|
181 |
"return the form-feed character"
|
|
182 |
|
|
183 |
^ Character value:12
|
|
184 |
!
|
|
185 |
|
|
186 |
ff
|
|
187 |
"return the form-feed character"
|
|
188 |
|
|
189 |
^ Character value:12
|
|
190 |
!
|
|
191 |
|
|
192 |
space
|
|
193 |
"return the blank character"
|
|
194 |
|
|
195 |
^ Character value:32
|
|
196 |
!
|
|
197 |
|
|
198 |
esc
|
|
199 |
"return the escape character"
|
|
200 |
|
|
201 |
^ Character value:27
|
|
202 |
!
|
|
203 |
|
|
204 |
quote
|
|
205 |
"return the single-quote character"
|
|
206 |
|
|
207 |
^ Character value:39
|
|
208 |
!
|
|
209 |
|
|
210 |
doubleQuote
|
|
211 |
"return the double-quote character"
|
|
212 |
|
|
213 |
^ Character value:34
|
|
214 |
!
|
|
215 |
|
|
216 |
excla
|
|
217 |
"return the exclamation-mark character"
|
|
218 |
^ $!!
|
|
219 |
! !
|
|
220 |
|
|
221 |
!Character methodsFor:'copying'!
|
|
222 |
|
154
|
223 |
copy
|
|
224 |
"return a copy of myself
|
|
225 |
reimplemented since characters are unique"
|
|
226 |
|
|
227 |
^ self
|
|
228 |
!
|
|
229 |
|
1
|
230 |
shallowCopy
|
|
231 |
"return a shallow copy of myself
|
|
232 |
reimplemented since characters are unique"
|
|
233 |
|
|
234 |
^ self
|
|
235 |
!
|
|
236 |
|
154
|
237 |
deepCopy
|
|
238 |
"return a deep copy of myself
|
|
239 |
reimplemented since characters are unique"
|
|
240 |
|
|
241 |
^ self
|
|
242 |
!
|
|
243 |
|
12
|
244 |
simpleDeepCopy
|
154
|
245 |
"return a deep copy of myself
|
12
|
246 |
reimplemented since characters are unique"
|
|
247 |
|
|
248 |
^ self
|
|
249 |
!
|
|
250 |
|
|
251 |
deepCopyUsing:aDictionary
|
154
|
252 |
"return a deep copy of myself
|
1
|
253 |
reimplemented since characters are unique"
|
|
254 |
|
|
255 |
^ self
|
|
256 |
! !
|
|
257 |
|
|
258 |
!Character methodsFor:'private accessing'!
|
|
259 |
|
|
260 |
setAsciiValue:anInteger
|
54
|
261 |
"very private - set the ascii value.
|
|
262 |
- use this only for characters with codes > 16rFF.
|
|
263 |
DANGER alert: funny things happen, if this is applied to
|
|
264 |
one of the fixed-characters 0..255."
|
1
|
265 |
|
|
266 |
asciivalue := anInteger
|
|
267 |
! !
|
2
|
268 |
|
1
|
269 |
!Character methodsFor:'accessing'!
|
|
270 |
|
|
271 |
asciiValue
|
54
|
272 |
"return the asciivalue of myself.
|
|
273 |
PP has removed this methhod with 4.1 and providing
|
|
274 |
asInteger instead."
|
1
|
275 |
|
|
276 |
^asciivalue
|
|
277 |
!
|
|
278 |
|
|
279 |
instVarAt:index put:anObject
|
54
|
280 |
"catch instvar access - asciivalue may not be changed"
|
1
|
281 |
|
|
282 |
self error:'Characters may not be modified'
|
|
283 |
! !
|
|
284 |
|
|
285 |
!Character methodsFor:'comparing'!
|
|
286 |
|
|
287 |
= aCharacter
|
|
288 |
"return true, if the argument, aCharacter is the same character
|
|
289 |
redefined to avoid the overhead of [Object =] -> [Object ==]
|
|
290 |
(although the compiler creates a shortcut code for this)"
|
|
291 |
|
|
292 |
^ (self == aCharacter)
|
|
293 |
!
|
|
294 |
|
|
295 |
~= aCharacter
|
|
296 |
"return true, if the argument, aCharacter is not the same character
|
|
297 |
redefined to avoid the overhead of [Object ~=] -> [Object not] -> [Object =] -> [Object ==]
|
|
298 |
(although the compiler creates a shortcut code for this)"
|
|
299 |
|
|
300 |
^ (self ~~ aCharacter)
|
|
301 |
!
|
|
302 |
|
|
303 |
> aCharacter
|
|
304 |
"return true, if the arguments asciiValue is less than mine"
|
|
305 |
|
|
306 |
^ (asciivalue > aCharacter asciiValue)
|
|
307 |
!
|
|
308 |
|
|
309 |
< aCharacter
|
|
310 |
"return true, if the arguments asciiValue is greater than mine"
|
|
311 |
|
|
312 |
^ (asciivalue < aCharacter asciiValue)
|
|
313 |
!
|
|
314 |
|
|
315 |
<= aCharacter
|
|
316 |
"return true, if the arguments asciiValue is greater or equal to mine"
|
|
317 |
|
|
318 |
^ (asciivalue <= aCharacter asciiValue)
|
|
319 |
!
|
|
320 |
|
|
321 |
>= aCharacter
|
|
322 |
"return true, if the arguments asciiValue is less or equal to mine"
|
|
323 |
|
|
324 |
^ (asciivalue >= aCharacter asciiValue)
|
|
325 |
!
|
|
326 |
|
|
327 |
identityHash
|
|
328 |
"return an integer useful for hashing on identity"
|
|
329 |
|
|
330 |
^ 4096 + asciivalue
|
|
331 |
! !
|
|
332 |
|
|
333 |
!Character methodsFor: 'arithmetic'!
|
|
334 |
|
|
335 |
+ aMagnitude
|
|
336 |
"Return the Character that is <aMagnitude> higher than the receiver.
|
|
337 |
Wrap if the resulting value is not a legal Character value. (JS)"
|
|
338 |
|
2
|
339 |
^ Character value:(asciivalue + aMagnitude asInteger \\ 256)
|
1
|
340 |
!
|
|
341 |
|
|
342 |
- aMagnitude
|
|
343 |
"Return the Character that is <aMagnitude> lower than the receiver.
|
68
|
344 |
Wrap if the resulting value is not a legal Character value. (JS)
|
|
345 |
claus: modified to return the difference as integer, if the argument
|
154
|
346 |
is another character"
|
1
|
347 |
|
68
|
348 |
aMagnitude isCharacter ifTrue:[
|
154
|
349 |
^ self asciiValue - aMagnitude asciiValue
|
68
|
350 |
].
|
2
|
351 |
^ Character value:(asciivalue - aMagnitude asInteger \\ 256)
|
68
|
352 |
|
|
353 |
"
|
|
354 |
$z - $a
|
|
355 |
$d - 3
|
|
356 |
"
|
1
|
357 |
!
|
|
358 |
|
|
359 |
// aMagnitude
|
|
360 |
"Return the Character who's value is the receiver divided by <aMagnitude>.
|
|
361 |
Wrap if the resulting value is not a legal Character value. (JS)"
|
|
362 |
|
2
|
363 |
^ Character value:(asciivalue // aMagnitude asInteger \\ 256)
|
1
|
364 |
!
|
|
365 |
|
|
366 |
\\ aMagnitude
|
|
367 |
"Return the Character who's value is the receiver modulo <aMagnitude>.
|
|
368 |
Wrap if the resulting value is not a legal Character value. (JS)"
|
|
369 |
|
2
|
370 |
^ Character value:(asciivalue \\ aMagnitude asInteger \\ 256)
|
1
|
371 |
! !
|
|
372 |
|
|
373 |
!Character methodsFor:'testing'!
|
|
374 |
|
54
|
375 |
isCharacter
|
|
376 |
"return true, if the receiver is some kind of character"
|
|
377 |
|
|
378 |
^ true
|
|
379 |
!
|
|
380 |
|
1
|
381 |
isDigit
|
|
382 |
"return true, if I am a digit (i.e. $0 .. $9)"
|
|
383 |
|
|
384 |
^ asciivalue between:($0 asciiValue) and:($9 asciiValue)
|
|
385 |
!
|
|
386 |
|
|
387 |
isDigitRadix:r
|
|
388 |
"return true, if I am a digit of a base r number"
|
|
389 |
|
|
390 |
(asciivalue < $0 asciiValue) ifTrue:[^ false].
|
|
391 |
(r > 10) ifTrue:[
|
154
|
392 |
(asciivalue between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[
|
|
393 |
^ true
|
|
394 |
].
|
|
395 |
((asciivalue - $a asciiValue) between:0 and:(r - 10)) ifTrue:[
|
|
396 |
^ true
|
|
397 |
].
|
|
398 |
^ (asciivalue - $A asciiValue) between:0 and:(r - 10)
|
1
|
399 |
].
|
|
400 |
(asciivalue - $0 asciiValue) < r ifTrue:[^ true].
|
|
401 |
^ false
|
|
402 |
!
|
|
403 |
|
|
404 |
isLowercase
|
|
405 |
"return true, if I am a lower-case letter"
|
|
406 |
|
|
407 |
%{ /* NOCONTEXT */
|
|
408 |
|
|
409 |
REGISTER int val;
|
|
410 |
|
|
411 |
val = _intVal(_INST(asciivalue));
|
54
|
412 |
#ifndef OLD
|
|
413 |
/* iso8859 puts national lower case characters at e0 .. ff */
|
|
414 |
if ((val >= 0xE0) && (val <= 0xFF)) {
|
154
|
415 |
RETURN(true);
|
54
|
416 |
}
|
|
417 |
#endif
|
1
|
418 |
RETURN ( ((val >= 'a') && (val <= 'z')) ? true : false );
|
|
419 |
%}
|
|
420 |
!
|
|
421 |
|
|
422 |
isUppercase
|
|
423 |
"return true, if I am an upper-case letter"
|
|
424 |
|
|
425 |
%{ /* NOCONTEXT */
|
|
426 |
|
|
427 |
REGISTER int val;
|
|
428 |
|
|
429 |
val = _intVal(_INST(asciivalue));
|
54
|
430 |
#ifndef OLD
|
|
431 |
/* iso8859 puts national upper case characters at c0 .. df */
|
|
432 |
if ((val >= 0xC0) && (val <= 0xDF)) {
|
154
|
433 |
RETURN(true);
|
54
|
434 |
}
|
|
435 |
#endif
|
1
|
436 |
RETURN ( ((val >= 'A') && (val <= 'Z')) ? true : false );
|
|
437 |
%}
|
|
438 |
!
|
|
439 |
|
|
440 |
isLetter
|
54
|
441 |
"return true, if I am a letter
|
|
442 |
- use isNationalLetter, if you are interrested in those."
|
1
|
443 |
|
|
444 |
%{ /*NOCONTEXT */
|
|
445 |
|
|
446 |
REGISTER int val;
|
|
447 |
|
|
448 |
val = _intVal(_INST(asciivalue));
|
|
449 |
RETURN ( (((val >= 'a') && (val <= 'z')) ||
|
154
|
450 |
((val >= 'A') && (val <= 'Z'))) ? true : false );
|
1
|
451 |
%}
|
|
452 |
!
|
|
453 |
|
154
|
454 |
isLetterOrDigit
|
54
|
455 |
"return true, if I am a letter or a digit
|
|
456 |
- use isNationalAlphaNumeric, if you are interrested in those."
|
1
|
457 |
|
|
458 |
%{ /* NOCONTEXT */
|
|
459 |
|
|
460 |
REGISTER int val;
|
|
461 |
|
|
462 |
val = _intVal(_INST(asciivalue));
|
|
463 |
if ((val >= 'a') && (val <= 'z')) {
|
154
|
464 |
RETURN ( true );
|
1
|
465 |
}
|
|
466 |
if ((val >= 'A') && (val <= 'Z')) {
|
154
|
467 |
RETURN ( true );
|
1
|
468 |
}
|
|
469 |
if ((val >= '0') && (val <= '9')) {
|
154
|
470 |
RETURN ( true );
|
1
|
471 |
}
|
|
472 |
RETURN ( false );
|
|
473 |
%}
|
|
474 |
!
|
|
475 |
|
154
|
476 |
isAlphaNumeric
|
|
477 |
"return true, if I am a letter or a digit
|
|
478 |
- same as isAlphaNumeric for compatibility reasons."
|
|
479 |
|
|
480 |
^ self isLetterOrDigit
|
|
481 |
!
|
|
482 |
|
1
|
483 |
isVowel
|
|
484 |
"return true, if I am a vowel (lower- or uppercase)"
|
|
485 |
|
|
486 |
(self == $a) ifTrue:[^ true].
|
|
487 |
(self == $e) ifTrue:[^ true].
|
|
488 |
(self == $i) ifTrue:[^ true].
|
|
489 |
(self == $o) ifTrue:[^ true].
|
|
490 |
(self == $u) ifTrue:[^ true].
|
|
491 |
(self == $A) ifTrue:[^ true].
|
|
492 |
(self == $E) ifTrue:[^ true].
|
|
493 |
(self == $I) ifTrue:[^ true].
|
|
494 |
(self == $O) ifTrue:[^ true].
|
|
495 |
(self == $U) ifTrue:[^ true].
|
|
496 |
^ false
|
|
497 |
!
|
|
498 |
|
|
499 |
isSeparator
|
|
500 |
"return true if I am a space, cr, tab, nl, or newPage"
|
|
501 |
|
|
502 |
%{ /* NOCONTEXT */
|
|
503 |
|
|
504 |
REGISTER int val;
|
|
505 |
|
|
506 |
val = _intVal(_INST(asciivalue));
|
|
507 |
if (val <= ' ') {
|
154
|
508 |
if ((val == ' ')
|
|
509 |
|| (val == '\n')
|
|
510 |
|| (val == '\t')
|
|
511 |
|| (val == '\r')
|
|
512 |
|| (val == '\f')) {
|
|
513 |
RETURN ( true );
|
|
514 |
}
|
1
|
515 |
}
|
|
516 |
%}
|
|
517 |
.
|
|
518 |
^ false
|
|
519 |
!
|
|
520 |
|
|
521 |
isEndOfLineCharacter
|
|
522 |
"return true if I am a line delimitting character"
|
|
523 |
|
|
524 |
%{ /* NOCONTEXT */
|
|
525 |
|
|
526 |
REGISTER int val;
|
|
527 |
|
|
528 |
val = _intVal(_INST(asciivalue));
|
|
529 |
if (val <= ' ') {
|
154
|
530 |
if ((val == '\n')
|
|
531 |
|| (val == '\r')
|
|
532 |
|| (val == '\f')) {
|
|
533 |
RETURN ( true );
|
|
534 |
}
|
1
|
535 |
}
|
|
536 |
%}
|
|
537 |
.
|
|
538 |
^ false
|
68
|
539 |
!
|
|
540 |
|
|
541 |
isPrintable
|
|
542 |
"return true, if the receiver is a useful printable character
|
|
543 |
(see fileBrowsers showFile:-method on how it can be used)"
|
|
544 |
|
|
545 |
(asciivalue between:32 and:127) ifTrue:[^ true].
|
|
546 |
asciivalue == 13 ifTrue:[^ true].
|
|
547 |
asciivalue == 9 ifTrue:[^ true].
|
|
548 |
asciivalue == 10 ifTrue:[^ true].
|
|
549 |
^ self isNationalLetter
|
|
550 |
|
1
|
551 |
! !
|
|
552 |
|
10
|
553 |
!Character methodsFor:'national testing'!
|
|
554 |
|
|
555 |
isNationalLetter
|
|
556 |
"return true, if the receiver is a letter in the
|
|
557 |
current language (Language variable)"
|
|
558 |
|
|
559 |
"stupid - should be configurable from a table ...
|
|
560 |
... good thing is, that iso8859 puts all national
|
154
|
561 |
characters above 16rC0"
|
10
|
562 |
|
|
563 |
self isLetter ifTrue:[^ true].
|
|
564 |
^ self asciiValue between:16rC0 and:16rFF
|
|
565 |
!
|
|
566 |
|
|
567 |
isNationalAlphaNumeric
|
|
568 |
"return true, if the receiver is a letter in the
|
|
569 |
current language (Language variable)"
|
|
570 |
|
|
571 |
"stupid - should be configurable from a table ...
|
|
572 |
... good thing is, that iso8859 puts all national
|
154
|
573 |
characters above 16rC0"
|
10
|
574 |
|
154
|
575 |
self isLetterOrDigit ifTrue:[^ true].
|
10
|
576 |
^ self asciiValue between:16rC0 and:16rFF
|
|
577 |
! !
|
|
578 |
|
1
|
579 |
!Character methodsFor:'converting'!
|
|
580 |
|
|
581 |
asLowercase
|
54
|
582 |
"return a character with same letter as the receiver,
|
|
583 |
but lowercase (the receiver if its lowercase or nonLetter)"
|
1
|
584 |
|
|
585 |
self isUppercase ifFalse:[^ self].
|
|
586 |
^ Character value:(asciivalue + 32)
|
|
587 |
!
|
|
588 |
|
|
589 |
asUppercase
|
54
|
590 |
"return a character with same letter as the receiver,
|
|
591 |
but uppercase (the receiver if its uppercase or nonLetter)"
|
1
|
592 |
|
|
593 |
self isLowercase ifFalse:[^ self].
|
|
594 |
^ Character value:(asciivalue - 32)
|
|
595 |
!
|
|
596 |
|
154
|
597 |
asCharacter
|
|
598 |
^ self
|
|
599 |
!
|
|
600 |
|
1
|
601 |
asInteger
|
54
|
602 |
"return an Integer with my ascii-value.
|
|
603 |
OWST4.2 compatibility (sigh)"
|
1
|
604 |
|
|
605 |
^ asciivalue
|
|
606 |
!
|
|
607 |
|
|
608 |
asSymbol
|
|
609 |
"return a unique symbol which prints like I print"
|
|
610 |
|
|
611 |
^ Symbol internCharacter:self
|
|
612 |
!
|
|
613 |
|
|
614 |
asString
|
|
615 |
"return a string of len 1 with myself as contents"
|
|
616 |
|
|
617 |
%{ /* NOCONTEXT */
|
|
618 |
|
|
619 |
char buffer[2];
|
|
620 |
|
|
621 |
buffer[0] = (char) _intVal(_characterVal(self));
|
|
622 |
buffer[1] = '\0';
|
|
623 |
RETURN ( _MKSTRING(buffer COMMA_SND) );
|
|
624 |
%}
|
|
625 |
|
|
626 |
"
|
154
|
627 |
the above is equivalent to the code below,
|
|
628 |
but slightly faster
|
|
629 |
"
|
|
630 |
|
|
631 |
"
|
1
|
632 |
|newString|
|
|
633 |
|
|
634 |
newString := String new:1.
|
|
635 |
newString at:1 put:self.
|
|
636 |
^ newString
|
|
637 |
"
|
|
638 |
!
|
|
639 |
|
154
|
640 |
digitValue
|
|
641 |
"return my digitValue for any base"
|
|
642 |
|
|
643 |
|ascii "{ Class: SmallInteger }" |
|
|
644 |
|
|
645 |
ascii := asciivalue.
|
|
646 |
(ascii between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[
|
|
647 |
^ ascii - $0 asciiValue
|
|
648 |
].
|
|
649 |
(ascii between:($a asciiValue) and:($z asciiValue)) ifTrue:[
|
|
650 |
^ ascii + (10 - $a asciiValue)
|
|
651 |
].
|
|
652 |
(ascii between:($A asciiValue) and:($Z asciiValue)) ifTrue:[
|
|
653 |
^ ascii + (10 - $A asciiValue)
|
|
654 |
].
|
|
655 |
|
|
656 |
"remove error below for X3J20 conformance ... "
|
|
657 |
self error:'bad character'.
|
|
658 |
" "
|
|
659 |
^ -1
|
|
660 |
!
|
|
661 |
|
1
|
662 |
to:aMagnitude
|
|
663 |
"Return an Interval over the characters from the receiver to <aMagnitude>.
|
|
664 |
Wrap <aMagnitude> if it is not a legal Character value. (JS)"
|
|
665 |
|
|
666 |
^ Interval from:self to:(aMagnitude \\ 256)
|
2
|
667 |
! !
|
1
|
668 |
|
2
|
669 |
!Character methodsFor:'enumeration'!
|
|
670 |
|
|
671 |
to:stopCharacter do:aBlock
|
|
672 |
"evaluate aBlock for each character in self .. stopCharacter.
|
|
673 |
This is somewhat stupid, since it depends on the ascii encoding
|
|
674 |
(370-users watch out :-)"
|
|
675 |
|
|
676 |
|runChar|
|
|
677 |
|
|
678 |
runChar := self.
|
|
679 |
[runChar <= stopCharacter] whileTrue:[
|
154
|
680 |
aBlock value:runChar.
|
|
681 |
runChar := runChar + 1
|
2
|
682 |
]
|
|
683 |
! !
|
|
684 |
|
|
685 |
!Character methodsFor: 'binary storage'!
|
|
686 |
|
|
687 |
hasSpecialBinaryRepresentation
|
37
|
688 |
"return true, if the receiver has a special binary representation"
|
|
689 |
|
2
|
690 |
^ true
|
|
691 |
!
|
|
692 |
|
|
693 |
storeBinaryOn: stream manager: manager
|
37
|
694 |
"store a binary representation of the receiver on stream;
|
|
695 |
redefined, since characters are stored with a special type-code"
|
|
696 |
|
2
|
697 |
stream nextPut: manager codeForCharacter.
|
|
698 |
stream nextPut:(self asciiValue)
|
1
|
699 |
! !
|
|
700 |
|
|
701 |
!Character methodsFor:'printing & storing'!
|
|
702 |
|
12
|
703 |
isLiteral
|
37
|
704 |
"return true, if the receiver can be used as a literal
|
|
705 |
(i.e. can be used in constant arrays)"
|
12
|
706 |
|
|
707 |
^ true
|
|
708 |
!
|
|
709 |
|
1
|
710 |
printString
|
|
711 |
"return a string to print me"
|
|
712 |
|
|
713 |
^ self asString
|
|
714 |
!
|
|
715 |
|
|
716 |
printOn:aStream
|
|
717 |
"print myself on aStream"
|
|
718 |
|
|
719 |
aStream nextPut:self
|
|
720 |
!
|
|
721 |
|
|
722 |
print
|
|
723 |
"print myself on stdout"
|
|
724 |
|
|
725 |
%{ /* NOCONTEXT */
|
|
726 |
|
|
727 |
putchar(_intVal(_INST(asciivalue)));
|
|
728 |
%}
|
|
729 |
!
|
|
730 |
|
|
731 |
displayString
|
|
732 |
"return a string used when the receiver is to be displayed
|
|
733 |
in an inspector kind-of-thing"
|
|
734 |
|
|
735 |
^ self storeString
|
|
736 |
!
|
|
737 |
|
|
738 |
storeOn:aStream
|
|
739 |
"store myself on aStream"
|
|
740 |
|
|
741 |
(asciivalue between:33 and:127) ifFalse:[
|
154
|
742 |
(self == Character space) ifTrue:[
|
|
743 |
aStream nextPutAll:'(Character space)'.
|
|
744 |
^ self
|
|
745 |
].
|
|
746 |
(self == Character cr) ifTrue:[
|
|
747 |
aStream nextPutAll:'(Character cr)'.
|
|
748 |
^ self
|
|
749 |
].
|
|
750 |
(self == Character tab) ifTrue:[
|
|
751 |
aStream nextPutAll:'(Character tab)'.
|
|
752 |
^ self
|
|
753 |
].
|
|
754 |
aStream nextPutAll:'(Character value:'.
|
|
755 |
aStream nextPutAll:(asciivalue printString).
|
|
756 |
aStream nextPutAll:')'
|
1
|
757 |
] ifTrue:[
|
154
|
758 |
aStream nextPut:$$.
|
|
759 |
aStream nextPut:self
|
1
|
760 |
]
|
|
761 |
! !
|