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