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