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