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