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