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