author | Claus Gittinger <cg@exept.de> |
Tue, 17 Jun 2003 22:13:34 +0200 | |
changeset 7412 | daae29634e02 |
parent 7354 | b22823ab2232 |
child 7688 | 8494a4155037 |
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 |
||
7300 | 260 |
!Character class methodsFor:'Compatibility-ANSI'! |
5945 | 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 |
||
7261 | 473 |
!Character methodsFor:'Compatibility-ANSI'! |
5945 | 474 |
|
475 |
codePoint |
|
476 |
^ self asciiValue |
|
477 |
! ! |
|
5847 | 478 |
|
7261 | 479 |
!Character methodsFor:'Compatibility-Dolphin'! |
6324 | 480 |
|
7351
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
481 |
isAlphaNumeric |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
482 |
"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
|
483 |
Please use isLetterOrDigit for compatibility reasons (which is ANSI)." |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
484 |
|
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
485 |
^ self isLetterOrDigit |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
486 |
! |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
487 |
|
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
488 |
isAlphabetic |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
489 |
"return true, if I am a letter. |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
490 |
Please use isLetter for compatibility reasons (which is ANSI)." |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
491 |
|
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
492 |
^ self isLetter |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
493 |
! |
1f805a32d551
comments in isAlphaNumeric and isAlphabetic
Claus Gittinger <cg@exept.de>
parents:
7300
diff
changeset
|
494 |
|
6324 | 495 |
isControl |
7353 | 496 |
"return true if I am a control character (i.e. ascii value < 32)" |
497 |
||
498 |
^ self isControlCharacter |
|
6324 | 499 |
! |
500 |
||
501 |
isHexDigit |
|
7354 | 502 |
"return true if I am a valid hexadecimal digit" |
503 |
||
6324 | 504 |
^ '0123456789abcdefABCDEF' includes:self |
7354 | 505 |
|
506 |
" |
|
507 |
$a isHexDigit |
|
508 |
" |
|
6324 | 509 |
! |
510 |
||
511 |
isPunctuation |
|
6327 | 512 |
^ (asciivalue between:16r21 and:16r40) |
513 |
or:[ (asciivalue between:16r5B and:16r60) |
|
514 |
or:[ (asciivalue between:123 and:126) |
|
515 |
or:[ (asciivalue between:161 and:191) |
|
516 |
or:[ (asciivalue == 215 ) |
|
517 |
or:[ (asciivalue == 247 ) ]]]]] |
|
6324 | 518 |
! ! |
519 |
||
1 | 520 |
!Character methodsFor:'accessing'! |
521 |
||
522 |
asciiValue |
|
54 | 523 |
"return the asciivalue of myself. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
524 |
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
|
525 |
limited to 8bit characters. |
54 | 526 |
PP has removed this methhod with 4.1 and providing |
527 |
asInteger instead." |
|
1 | 528 |
|
529 |
^asciivalue |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
530 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
531 |
"Modified: 27.6.1996 / 12:34:34 / cg" |
1 | 532 |
! |
533 |
||
534 |
instVarAt:index put:anObject |
|
54 | 535 |
"catch instvar access - asciivalue may not be changed" |
1 | 536 |
|
537 |
self error:'Characters may not be modified' |
|
2214 | 538 |
! |
539 |
||
540 |
newDigitValue |
|
541 |
"Answer 0-9 if the receiver is $0-$9, 10-35 if it is $A-$Z, and < 0 otherwise. |
|
542 |
This is used to parse literal numbers of radix 2-36." |
|
543 |
||
544 |
| code value | |
|
545 |
code := self asInteger. |
|
546 |
value := code - $0 asInteger. |
|
547 |
value <= 9 ifTrue: [^value]. |
|
548 |
value := code - $A asInteger. |
|
549 |
(value >= 0 and: [value < 26]) |
|
550 |
ifTrue: [^value + 10]. |
|
551 |
^-1 |
|
1 | 552 |
! ! |
553 |
||
699 | 554 |
!Character methodsFor:'arithmetic'! |
1 | 555 |
|
556 |
+ aMagnitude |
|
557 |
"Return the Character that is <aMagnitude> higher than the receiver. |
|
558 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
559 |
||
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
560 |
^ Character value:(asciivalue + aMagnitude asInteger \\ 16rFFFF) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
561 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
562 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
563 |
$A + 5 |
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 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
566 |
"Modified: 27.6.1996 / 12:34:51 / cg" |
1 | 567 |
! |
568 |
||
569 |
- aMagnitude |
|
570 |
"Return the Character that is <aMagnitude> lower than the receiver. |
|
68 | 571 |
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
|
572 |
claus: |
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
returned." |
1 | 576 |
|
68 | 577 |
aMagnitude isCharacter ifTrue:[ |
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
578 |
^ self asciiValue - aMagnitude asciiValue |
68 | 579 |
]. |
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
580 |
^ Character value:(asciivalue - aMagnitude asInteger \\ 16rFFFF) |
68 | 581 |
|
582 |
" |
|
583 |
$z - $a |
|
584 |
$d - 3 |
|
585 |
" |
|
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
586 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
587 |
"Modified: 27.6.1996 / 12:35:34 / cg" |
1 | 588 |
! |
589 |
||
590 |
// aMagnitude |
|
591 |
"Return the Character who's value is the receiver divided by <aMagnitude>. |
|
592 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
593 |
||
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
594 |
^ Character value:(asciivalue // aMagnitude asInteger \\ 16rFFFF) |
1 | 595 |
! |
596 |
||
597 |
\\ aMagnitude |
|
598 |
"Return the Character who's value is the receiver modulo <aMagnitude>. |
|
599 |
Wrap if the resulting value is not a legal Character value. (JS)" |
|
600 |
||
6531
8798c9a1d1e6
arithmetic wraps at 16bit bounds (unicode)
Claus Gittinger <cg@exept.de>
parents:
6527
diff
changeset
|
601 |
^ Character value:(asciivalue \\ aMagnitude asInteger \\ 16rFFFF) |
1 | 602 |
! ! |
603 |
||
699 | 604 |
!Character methodsFor:'binary storage'! |
605 |
||
606 |
hasSpecialBinaryRepresentation |
|
607 |
"return true, if the receiver has a special binary representation" |
|
608 |
||
609 |
^ true |
|
610 |
! |
|
611 |
||
612 |
storeBinaryOn:stream manager:manager |
|
613 |
"store a binary representation of the receiver on stream; |
|
614 |
redefined, since single-byte characters are stored more compact |
|
615 |
with a special type-code followed by the asciiValue." |
|
616 |
||
617 |
(asciivalue < 256) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
618 |
stream nextPut:manager codeForCharacter; nextPut:asciivalue. |
699 | 619 |
] ifFalse:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
620 |
stream nextPut:manager codeForTwoByteCharacter. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
621 |
stream nextPutShort:asciivalue MSB:true |
699 | 622 |
] |
623 |
! ! |
|
624 |
||
625 |
!Character methodsFor:'comparing'! |
|
626 |
||
627 |
< aCharacter |
|
628 |
"return true, if the arguments asciiValue is greater than mine" |
|
629 |
||
5315
04052c5626bf
allow compare against integers (asciiValue compare).
Claus Gittinger <cg@exept.de>
parents:
4728
diff
changeset
|
630 |
^ (asciivalue < aCharacter asInteger) |
699 | 631 |
! |
632 |
||
633 |
<= aCharacter |
|
634 |
"return true, if the arguments asciiValue is greater or equal to mine" |
|
635 |
||
5315
04052c5626bf
allow compare against integers (asciiValue compare).
Claus Gittinger <cg@exept.de>
parents:
4728
diff
changeset
|
636 |
^ (asciivalue <= aCharacter asInteger) |
699 | 637 |
! |
638 |
||
639 |
= aCharacter |
|
640 |
"return true, if the argument, aCharacter is the same character |
|
641 |
Redefined to take care of 16bit characters." |
|
642 |
||
643 |
self == aCharacter ifTrue:[^ true]. |
|
644 |
aCharacter isCharacter ifFalse:[^ false]. |
|
645 |
^ (asciivalue = aCharacter asciiValue) |
|
646 |
! |
|
647 |
||
648 |
> aCharacter |
|
649 |
"return true, if the arguments asciiValue is less than mine" |
|
650 |
||
5315
04052c5626bf
allow compare against integers (asciiValue compare).
Claus Gittinger <cg@exept.de>
parents:
4728
diff
changeset
|
651 |
^ (asciivalue > aCharacter asInteger) |
699 | 652 |
! |
653 |
||
654 |
>= aCharacter |
|
655 |
"return true, if the arguments asciiValue is less or equal to mine" |
|
656 |
||
5315
04052c5626bf
allow compare against integers (asciiValue compare).
Claus Gittinger <cg@exept.de>
parents:
4728
diff
changeset
|
657 |
^ (asciivalue >= aCharacter asInteger) |
699 | 658 |
! |
659 |
||
5540 | 660 |
hash |
661 |
"return an integer useful for hashing" |
|
662 |
||
663 |
^ asciivalue |
|
664 |
! |
|
665 |
||
699 | 666 |
identityHash |
667 |
"return an integer useful for hashing on identity" |
|
668 |
||
669 |
asciivalue <= 255 ifTrue:[ |
|
670 |
^ 4096 + asciivalue |
|
671 |
]. |
|
672 |
^ super identityHash |
|
673 |
! |
|
674 |
||
675 |
sameAs:aCharacter |
|
676 |
"return true, if the argument, aCharacter is the same character, |
|
677 |
ignoring case differences." |
|
678 |
||
679 |
self == aCharacter ifTrue:[^ true]. |
|
680 |
^ self asLowercase = aCharacter asLowercase |
|
681 |
! |
|
682 |
||
683 |
~= aCharacter |
|
684 |
"return true, if the argument, aCharacter is not the same character |
|
685 |
Redefined to take care of 16bit characters." |
|
686 |
||
687 |
self == aCharacter ifTrue:[^ false]. |
|
688 |
aCharacter isCharacter ifFalse:[^ true]. |
|
689 |
^ (asciivalue ~~ aCharacter asciiValue) |
|
690 |
! ! |
|
691 |
||
692 |
!Character methodsFor:'converting'! |
|
693 |
||
694 |
asCharacter |
|
695 |
"usually sent to integers, but redefined here to allow integers |
|
696 |
and characters to be used commonly without a need for a test." |
|
697 |
||
698 |
^ self |
|
699 |
||
700 |
" |
|
701 |
32 asCharacter |
|
702 |
" |
|
703 |
! |
|
704 |
||
705 |
asInteger |
|
706 |
"return an Integer with my ascii-value. |
|
707 |
OWST4.2 compatibility (sigh)" |
|
708 |
||
709 |
^ asciivalue |
|
710 |
! |
|
711 |
||
712 |
asLowercase |
|
713 |
"return a character with same letter as the receiver, |
|
714 |
but lowercase (the receiver if its lowercase or nonLetter)" |
|
715 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
716 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
717 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
718 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
719 |
"/ self isUppercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
720 |
"/ ^ Character value:(asciivalue + 32) |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
721 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
722 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
723 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
724 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
725 |
((code >= $A asciiValue) and:[code <= $Z asciiValue]) ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
726 |
^ Character value:(code + ($a asciiValue - $A asciiValue)) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
727 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
728 |
code < 16r00C0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
729 |
code < 16r0100 ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
730 |
code >= 16r00DF ifTrue:[^ self]. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
731 |
code == 16r00D7 ifTrue:[^ self]. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
732 |
^ Character value:(code + 16r20) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
733 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
734 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
735 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
736 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
737 |
|
2124 | 738 |
'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
|
739 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
740 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
741 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
742 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
743 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
744 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
745 |
|
2124 | 746 |
"Modified: 10.1.1997 / 15:35:44 / cg" |
699 | 747 |
! |
748 |
||
749 |
asString |
|
750 |
"return a string of len 1 with myself as contents" |
|
751 |
||
752 |
%{ /* NOCONTEXT */ |
|
753 |
char buffer[2]; |
|
754 |
OBJ s; |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
755 |
unsigned val; |
699 | 756 |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
757 |
val = __intVal(_characterVal(self)); |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
758 |
if (val <= 0xFF) { |
5407 | 759 |
buffer[0] = (char) val; |
760 |
buffer[1] = '\0'; |
|
761 |
s = __MKSTRING_L(buffer, 1 COMMA_SND); |
|
762 |
if (s != nil) { |
|
763 |
RETURN (s); |
|
764 |
} |
|
699 | 765 |
} |
766 |
%}. |
|
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
767 |
asciivalue > 255 ifTrue:[ |
5407 | 768 |
^ (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
|
769 |
]. |
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
770 |
|
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
771 |
|
5407 | 772 |
^ (String new:1) at:1 put:self; yourself. |
699 | 773 |
! |
774 |
||
775 |
asSymbol |
|
776 |
"return a unique symbol which prints like I print" |
|
777 |
||
778 |
^ Symbol internCharacter:self |
|
779 |
! |
|
780 |
||
6029 | 781 |
asUnicodeString |
782 |
"return a unicode string of len 1 with myself as contents" |
|
783 |
||
784 |
^ (UnicodeString new:1) at:1 put:self; yourself. |
|
785 |
! |
|
786 |
||
699 | 787 |
asUppercase |
788 |
"return a character with same letter as the receiver, |
|
789 |
but uppercase (the receiver if its uppercase or nonLetter)" |
|
790 |
||
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
791 |
|code "{Class: SmallInteger }"| |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
792 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
793 |
"/ the old code: |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
794 |
"/ self isLowercase ifFalse:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
795 |
"/ ^ Character value:(asciivalue - 32) |
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 |
code := asciivalue. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
798 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
799 |
"/ ISO Latin-1 |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
800 |
((code >= $a asciiValue) and:[code <= $z asciiValue]) ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
801 |
^ Character value:(code + ($A asciiValue - $a asciiValue)) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
802 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
803 |
code < 16r00E0 ifTrue:[^ self]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
804 |
code < 16r0100 ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
805 |
code == 16r00F7 ifTrue:[^ self]. "/ division |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
806 |
"/ 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
|
807 |
code == 16r00FF ifTrue:[^ self]. |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
808 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
809 |
^ Character value:(code - 16r20) |
1491
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
810 |
]. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
811 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
812 |
"/ mhmh - in which encoding is this character. |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
813 |
"/ here, assume Unicode |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
814 |
|
2124 | 815 |
'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
|
816 |
^ self |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
817 |
|
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
818 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
819 |
$A asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
820 |
$1 asLowercase |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
821 |
" |
a42ae3fbb756
fixed asLowercase / asUppercase for national characters
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
822 |
|
2124 | 823 |
"Modified: 10.1.1997 / 15:35:51 / cg" |
699 | 824 |
! |
825 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
826 |
decodeAsLiteralArray |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
827 |
"given a literalEncoding in the receiver, |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
828 |
create & return the corresponding object. |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
829 |
The inverse operation to #literalArrayEncoding." |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
830 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
831 |
^ self |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
832 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
833 |
"Created: / 27.10.1997 / 14:40:16 / cg" |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
834 |
! |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
835 |
|
699 | 836 |
digitValue |
837 |
"return my digitValue for any base" |
|
838 |
||
839 |
|ascii "{ Class: SmallInteger }" | |
|
840 |
||
841 |
ascii := asciivalue. |
|
842 |
(ascii between:($0 asciiValue) and:($9 asciiValue)) ifTrue:[ |
|
843 |
^ ascii - $0 asciiValue |
|
844 |
]. |
|
845 |
(ascii between:($a asciiValue) and:($z asciiValue)) ifTrue:[ |
|
846 |
^ ascii + (10 - $a asciiValue) |
|
847 |
]. |
|
848 |
(ascii between:($A asciiValue) and:($Z asciiValue)) ifTrue:[ |
|
849 |
^ ascii + (10 - $A asciiValue) |
|
850 |
]. |
|
851 |
||
852 |
"remove error below for X3J20 conformance ... " |
|
853 |
self error:'bad character'. |
|
854 |
" " |
|
855 |
^ -1 |
|
856 |
! |
|
857 |
||
3058
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
858 |
literalArrayEncoding |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
859 |
"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
|
860 |
can be reconstructed with #decodeAsLiteralArray." |
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
861 |
|
187372cf3eb8
added #encodeAsLiteralArray & #decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
862 |
^ self |
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 |
"Created: / 27.10.1997 / 14:40:37 / cg" |
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 |
|
699 | 867 |
to:aMagnitude |
868 |
"Return an Interval over the characters from the receiver to <aMagnitude>. |
|
869 |
Wrap <aMagnitude> if it is not a legal Character value. (JS)" |
|
870 |
||
871 |
^ Interval from:self to:(aMagnitude \\ 256) |
|
5847 | 872 |
! |
873 |
||
874 |
utf8Encoded |
|
875 |
"convert a character from ISO8859-1 to its UTF-8 encoding. |
|
876 |
this returns a String" |
|
877 |
||
878 |
|s| |
|
879 |
||
880 |
s := (String new:6) writeStream. |
|
881 |
self utf8EncodedOn:s. |
|
882 |
^ s contents |
|
883 |
! |
|
884 |
||
885 |
utf8EncodedOn:aStream |
|
6808 | 886 |
"append my UTF-8 representation to the argument, aStream. |
887 |
Up to 31 bits can be encoded in up to 6 bytes. |
|
888 |
However, currently, characters are limited to 16 bits." |
|
5847 | 889 |
|
890 |
|b1 b2 b3 b4 b5 v| |
|
891 |
||
892 |
asciivalue <= 16r7F ifTrue:[ |
|
893 |
aStream nextPut:self. |
|
894 |
^ self. |
|
895 |
]. |
|
896 |
||
6808 | 897 |
b1 := Character value:((asciivalue bitAnd:16r3F) bitOr:2r10000000). |
5847 | 898 |
v := asciivalue bitShift:-6. |
899 |
v <= 16r1F ifTrue:[ |
|
6808 | 900 |
aStream nextPut:(Character value:(v bitOr:2r11000000)). |
5847 | 901 |
aStream nextPut:b1. |
902 |
^ self. |
|
903 |
]. |
|
6808 | 904 |
b2 := Character value:((v bitAnd:16r3F) bitOr:2r10000000). |
5847 | 905 |
v := v bitShift:-6. |
906 |
v <= 16r0F ifTrue:[ |
|
6808 | 907 |
aStream nextPut:(Character value:(v bitOr:2r11100000)). |
5847 | 908 |
aStream nextPut:b2. |
909 |
aStream nextPut:b1. |
|
910 |
^ self. |
|
911 |
]. |
|
6808 | 912 |
b3 := Character value:((v bitAnd:16r3F) bitOr:2r10000000). |
5847 | 913 |
v := v bitShift:-6. |
914 |
v <= 16r07 ifTrue:[ |
|
6808 | 915 |
aStream nextPut:(Character value:(v bitOr:2r11110000)). |
5847 | 916 |
aStream nextPut:b3. |
917 |
aStream nextPut:b2. |
|
918 |
aStream nextPut:b1. |
|
919 |
^ self. |
|
920 |
]. |
|
6808 | 921 |
b4 := Character value:((v bitAnd:16r3F) bitOr:2r10000000). |
5847 | 922 |
v := v bitShift:-6. |
923 |
v <= 16r03 ifTrue:[ |
|
6808 | 924 |
aStream nextPut:(Character value:(v bitOr:2r11111000)). |
5847 | 925 |
aStream nextPut:b4. |
926 |
aStream nextPut:b3. |
|
927 |
aStream nextPut:b2. |
|
928 |
aStream nextPut:b1. |
|
929 |
^ self. |
|
930 |
]. |
|
6808 | 931 |
b5 := Character value:((v bitAnd:16r3F) bitOr:2r10000000). |
5847 | 932 |
v := v bitShift:-6. |
933 |
v <= 16r01 ifTrue:[ |
|
6808 | 934 |
aStream nextPut:(Character value:(v bitOr:2r11111100)). |
5847 | 935 |
aStream nextPut:b5. |
936 |
aStream nextPut:b4. |
|
937 |
aStream nextPut:b3. |
|
938 |
aStream nextPut:b2. |
|
939 |
aStream nextPut:b1. |
|
940 |
^ self. |
|
941 |
]. |
|
6808 | 942 |
"/ cannot happen - we only support up to 16 bit characters |
943 |
self error:'ascii value > 31bit in utf8Encode'. |
|
5847 | 944 |
|
945 |
" |
|
6527 | 946 |
$a utf8Encoded |
947 |
$ü utf8Encoded asByteArray |
|
948 |
(Character value:16r1fff) utf8Encoded asByteArray |
|
6808 | 949 |
(Character value:16rffff) utf8Encoded asByteArray |
950 |
(Character value:16r800) utf8Encoded asByteArray |
|
5847 | 951 |
" |
699 | 952 |
! ! |
953 |
||
954 |
!Character methodsFor:'copying'! |
|
955 |
||
956 |
copy |
|
957 |
"return a copy of myself |
|
958 |
reimplemented since characters are unique" |
|
959 |
||
960 |
^ self |
|
961 |
! |
|
962 |
||
2214 | 963 |
copyUpToLast: char |
964 |
||
965 |
^self |
|
966 |
! |
|
967 |
||
699 | 968 |
deepCopyUsing:aDictionary |
969 |
"return a deep copy of myself |
|
4728 | 970 |
reimplemented since characters are immutable" |
699 | 971 |
|
972 |
^ self |
|
973 |
! |
|
974 |
||
975 |
shallowCopy |
|
976 |
"return a shallow copy of myself |
|
4728 | 977 |
reimplemented since characters are immutable" |
699 | 978 |
|
979 |
^ self |
|
980 |
! |
|
981 |
||
982 |
simpleDeepCopy |
|
983 |
"return a deep copy of myself |
|
4728 | 984 |
reimplemented since characters are immutable" |
699 | 985 |
|
986 |
^ self |
|
987 |
! ! |
|
988 |
||
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
989 |
!Character methodsFor:'encoding'! |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
990 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
991 |
encodeOn:anEncoder with:aParameter |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
992 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
993 |
anEncoder encodeCharacter:self with:aParameter |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
994 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
995 |
|
6508 | 996 |
! |
997 |
||
998 |
rot13 |
|
999 |
"Usenet: from `rotate alphabet 13 places'] |
|
1000 |
The simple Caesar-cypher encryption that replaces each English |
|
1001 |
letter with the one 13 places forward or back along the alphabet, |
|
1002 |
so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' |
|
1003 |
Most Usenet news reading and posting programs include a rot13 feature. |
|
1004 |
It is used to enclose the text in a sealed wrapper that the reader must choose |
|
1005 |
to open -- e.g., for posting things that might offend some readers, or spoilers. |
|
1006 |
A major advantage of rot13 over rot(N) for other N is that it |
|
1007 |
is self-inverse, so the same code can be used for encoding and decoding." |
|
1008 |
||
1009 |
((self >= $a) & (self < $n)) | ((self >= $A) & (self < $N)) |
|
1010 |
ifTrue: [ ^ Character value:(self asciiValue + 13) ]. |
|
1011 |
((self > $m) & (self <= $z)) | ((self > $M) & (self <= $Z)) |
|
1012 |
ifTrue: [ ^ Character value:(self asciiValue - 13) ]. |
|
1013 |
^ self |
|
1014 |
||
1015 |
" |
|
1016 |
$h rot13 |
|
1017 |
$h rot13 rot13 |
|
7250 | 1018 |
'The butler did it!!' rot13 |
6508 | 1019 |
" |
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
1020 |
! ! |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5452
diff
changeset
|
1021 |
|
699 | 1022 |
!Character methodsFor:'national testing'! |
1023 |
||
1024 |
isNationalAlphaNumeric |
|
2214 | 1025 |
"return true, if the receiver is a letter or digit in the |
699 | 1026 |
current language (Language variable)" |
1027 |
||
1028 |
"stupid - should be configurable from a table ... |
|
1029 |
... good thing is, that iso8859 puts all national |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1030 |
characters above 16rC0" |
699 | 1031 |
|
1032 |
self isLetterOrDigit ifTrue:[^ true]. |
|
2214 | 1033 |
^ self isNationalLetter |
1034 |
||
1035 |
"Modified: 21.1.1997 / 11:10:54 / cg" |
|
699 | 1036 |
! |
1037 |
||
1038 |
isNationalLetter |
|
1039 |
"return true, if the receiver is a letter in the |
|
1040 |
current language (Language variable)" |
|
1041 |
||
1042 |
"stupid - should be configurable from a table ... |
|
1043 |
... good thing is, that iso8859 puts all national |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1044 |
characters above 16rC0" |
2214 | 1045 |
|
699 | 1046 |
self isLetter ifTrue:[^ true]. |
2214 | 1047 |
(asciivalue between:16rC0 and:16rD6) ifTrue:[^ true]. |
1048 |
(asciivalue between:16rD8 and:16rF6) ifTrue:[^ true]. |
|
1049 |
(asciivalue between:16rF8 and:16rFF) ifTrue:[^ true]. |
|
1050 |
^ false. |
|
1051 |
||
1052 |
"Modified: 21.1.1997 / 11:13:02 / cg" |
|
699 | 1053 |
! ! |
1054 |
||
1055 |
!Character methodsFor:'printing & storing'! |
|
1056 |
||
1057 |
displayString |
|
1058 |
"return a string used when the receiver is to be displayed |
|
1059 |
in an inspector kind-of-thing" |
|
1060 |
||
2908 | 1061 |
^ (self storeString , ' "16r' , (asciivalue printStringRadix:16) , '"') |
699 | 1062 |
! |
1063 |
||
1064 |
isLiteral |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1065 |
"return true, if the receiver can be used as a literal constant in ST syntax |
699 | 1066 |
(i.e. can be used in constant arrays)" |
1067 |
||
1068 |
^ true |
|
1069 |
! |
|
1070 |
||
1071 |
||
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1072 |
"print myself on stdout. |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1073 |
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
|
1074 |
will therefore work even in case of emergency (but only, if Stdout is nil)." |
699 | 1075 |
|
1076 |
%{ /* NOCONTEXT */ |
|
1077 |
||
5746
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1078 |
if (@global(Stdout) == nil) { |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1079 |
putchar(__intVal(__INST(asciivalue))); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1080 |
RETURN(self); |
cf5e42cb72ef
do not overwrite the standard printing conventions
Claus Gittinger <cg@exept.de>
parents:
5566
diff
changeset
|
1081 |
} |
5452
71fd110c347a
allow print, printCR during early initialization
Claus Gittinger <cg@exept.de>
parents:
5433
diff
changeset
|
1082 |
%}. |
71fd110c347a
allow print, printCR during early initialization
Claus Gittinger <cg@exept.de>
parents:
5433
diff
changeset
|
1083 |
super print |
699 | 1084 |
! |
1085 |
||
1086 |
printOn:aStream |
|
1087 |
"print myself on aStream" |
|
1088 |
||
1089 |
aStream nextPut:self |
|
1090 |
! |
|
1091 |
||
1092 |
printString |
|
1093 |
"return a string to print me" |
|
1094 |
||
1095 |
^ self asString |
|
1096 |
! |
|
1097 |
||
2214 | 1098 |
reconstructOn:aStream |
1099 |
aStream nextPut:$$; nextPut:self |
|
1100 |
||
1101 |
"Created: 6.2.1996 / 09:46:12 / stefan" |
|
1102 |
"Modified: 6.2.1996 / 10:57:35 / stefan" |
|
1103 |
! |
|
1104 |
||
699 | 1105 |
storeOn:aStream |
1106 |
"store myself on aStream" |
|
1107 |
||
1108 |
|special| |
|
1109 |
||
1110 |
(asciivalue between:33 and:127) ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1111 |
(self == Character space) ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1112 |
special := 'space' |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1113 |
] ifFalse:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1114 |
(self == Character cr) ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1115 |
special := 'cr'. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1116 |
] ifFalse:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1117 |
(self == Character tab) ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1118 |
special := 'tab'. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1119 |
] ifFalse:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1120 |
(self == Character esc) ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1121 |
special := 'esc'. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1122 |
] |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1123 |
] |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1124 |
] |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1125 |
]. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1126 |
special notNil ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1127 |
aStream nextPutAll:'(Character '; nextPutAll:special; nextPut:$). |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1128 |
^ self |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1129 |
]. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1130 |
aStream nextPutAll:'(Character value:16r'. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1131 |
asciivalue printOn:aStream base:16. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1132 |
aStream nextPut:$) |
699 | 1133 |
] ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1134 |
aStream nextPut:$$; nextPut:self |
699 | 1135 |
] |
995
b018368b3a94
asString to 16-bit char should return a twoByteString
Claus Gittinger <cg@exept.de>
parents:
819
diff
changeset
|
1136 |
|
3190
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
1137 |
"Modified: / 23.2.1996 / 23:27:32 / cg" |
81ffb25d1d86
Use #printOn: instead of #printString
Stefan Vogel <sv@exept.de>
parents:
3072
diff
changeset
|
1138 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
699 | 1139 |
! ! |
1140 |
||
7257 | 1141 |
!Character methodsFor:'private-accessing'! |
699 | 1142 |
|
1143 |
setAsciiValue:anInteger |
|
1144 |
"very private - set the ascii value. |
|
1145 |
- use this only for characters with codes > 16rFF. |
|
1146 |
DANGER alert: funny things happen, if this is applied to |
|
1147 |
one of the fixed-characters 0..255." |
|
1148 |
||
1149 |
asciivalue := anInteger |
|
1150 |
! ! |
|
1151 |
||
1 | 1152 |
!Character methodsFor:'testing'! |
1153 |
||
54 | 1154 |
isCharacter |
1155 |
"return true, if the receiver is some kind of character" |
|
1156 |
||
1157 |
^ true |
|
1158 |
! |
|
1159 |
||
3667 | 1160 |
isControlCharacter |
1161 |
"return true if I am a control character (i.e. ascii value < 32)" |
|
1162 |
||
1163 |
%{ /* NOCONTEXT */ |
|
1164 |
#ifdef NON_ASCII /* i.e. EBCDIC ;-) */ |
|
1165 |
not yet implemented - fails when compiled |
|
1166 |
#else |
|
1167 |
REGISTER int val; |
|
1168 |
||
1169 |
val = __intVal(__INST(asciivalue)); |
|
3881 | 1170 |
if (val < ' ') { |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1171 |
RETURN ( true ); |
3667 | 1172 |
} |
1173 |
#endif |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1174 |
RETURN (false); |
3667 | 1175 |
%}. |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1176 |
^ asciivalue < 16r20. |
3667 | 1177 |
|
1178 |
" |
|
1179 |
(Character value:1) isControlCharacter |
|
1180 |
$a isControlCharacter |
|
1181 |
" |
|
1182 |
! |
|
1183 |
||
1 | 1184 |
isDigit |
1185 |
"return true, if I am a digit (i.e. $0 .. $9)" |
|
1186 |
||
6527 | 1187 |
%{ /*NOCONTEXT */ |
1188 |
||
1189 |
REGISTER int val; |
|
1190 |
||
1191 |
val = __intVal(__INST(asciivalue)); |
|
1192 |
if ((unsigned)(val - '0') <= ('9' - '0')) { |
|
1193 |
RETURN ( true ); |
|
1194 |
} |
|
1195 |
RETURN ( false ); |
|
1196 |
%}. |
|
1197 |
^ asciivalue between:$0 asciiValue and:$9 asciiValue |
|
1 | 1198 |
! |
1199 |
||
1200 |
isDigitRadix:r |
|
1201 |
"return true, if I am a digit of a base r number" |
|
1202 |
||
1203 |
(asciivalue < $0 asciiValue) ifTrue:[^ false]. |
|
1204 |
(r > 10) ifTrue:[ |
|
6527 | 1205 |
(asciivalue <= $9 asciiValue) ifTrue:[ |
1206 |
^ true |
|
1207 |
]. |
|
1208 |
((asciivalue - $a asciiValue) between:0 and:(r - 11)) ifTrue:[ |
|
1209 |
^ true |
|
1210 |
]. |
|
1211 |
^ (asciivalue - $A asciiValue) between:0 and:(r - 11) |
|
1 | 1212 |
]. |
1213 |
(asciivalue - $0 asciiValue) < r ifTrue:[^ true]. |
|
1214 |
^ false |
|
1215 |
! |
|
1216 |
||
699 | 1217 |
isEndOfLineCharacter |
1218 |
"return true if I am a line delimitting character" |
|
1 | 1219 |
|
1220 |
%{ /* NOCONTEXT */ |
|
1221 |
||
1222 |
REGISTER int val; |
|
1223 |
||
1133 | 1224 |
val = __intVal(__INST(asciivalue)); |
699 | 1225 |
if ((val == '\n') |
1226 |
|| (val == '\r') |
|
1227 |
|| (val == '\f')) { |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1228 |
RETURN ( true ); |
54 | 1229 |
} |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1230 |
RETURN (false); |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1231 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1232 |
^ asciivalue == 16r0A |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1233 |
or:[asciivalue == 16r0D |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1234 |
or:[asciivalue == 16r0C]] |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1235 |
|
1 | 1236 |
! |
1237 |
||
5473
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1238 |
isImmediate |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1239 |
"return true if I am an immediate object |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1240 |
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
|
1241 |
no real object header/storage is used me. |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1242 |
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
|
1243 |
also return true here" |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1244 |
|
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1245 |
^ asciivalue <= 255 |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1246 |
|
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1247 |
! |
c48d8c45c740
isImmediate returns true for shared characters
Claus Gittinger <cg@exept.de>
parents:
5471
diff
changeset
|
1248 |
|
1 | 1249 |
isLetter |
54 | 1250 |
"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
|
1251 |
- use isNationalLetter, if you are interested in those." |
1 | 1252 |
|
1253 |
%{ /*NOCONTEXT */ |
|
1254 |
||
1255 |
REGISTER int val; |
|
1256 |
||
1133 | 1257 |
val = __intVal(__INST(asciivalue)); |
6527 | 1258 |
if ((unsigned)(val - 'a') <= ('z' - 'a')) { |
1259 |
RETURN ( true ); |
|
1260 |
} |
|
1261 |
if ((unsigned)(val - 'A') <= ('Z' - 'A')) { |
|
1262 |
RETURN ( true ); |
|
1263 |
} |
|
1264 |
RETURN ( false ); |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1265 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1266 |
^ (asciivalue between:($a asciiValue) and:($z asciiValue)) |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1267 |
or:[(asciivalue between:($A asciiValue) and:($Z asciiValue))] |
1 | 1268 |
! |
1269 |
||
154 | 1270 |
isLetterOrDigit |
54 | 1271 |
"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
|
1272 |
- use isNationalAlphaNumeric, if you are interested in those." |
1 | 1273 |
|
1274 |
%{ /* NOCONTEXT */ |
|
1275 |
||
1276 |
REGISTER int val; |
|
1277 |
||
1133 | 1278 |
val = __intVal(__INST(asciivalue)); |
6527 | 1279 |
if ((unsigned)(val - 'a') <= ('z' - 'a')) { |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1280 |
RETURN ( true ); |
1 | 1281 |
} |
6527 | 1282 |
if ((unsigned)(val - 'A') <= ('Z' - 'A')) { |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1283 |
RETURN ( true ); |
1 | 1284 |
} |
6527 | 1285 |
if ((unsigned)(val - '0') <= ('9' - '0')) { |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1286 |
RETURN ( true ); |
1 | 1287 |
} |
1288 |
RETURN ( false ); |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1289 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1290 |
^ self isLetter or:[self isDigit] |
1 | 1291 |
! |
1292 |
||
699 | 1293 |
isLowercase |
1294 |
"return true, if I am a lower-case letter" |
|
1295 |
||
1296 |
%{ /* NOCONTEXT */ |
|
1297 |
||
1298 |
REGISTER int val; |
|
154 | 1299 |
|
1133 | 1300 |
val = __intVal(__INST(asciivalue)); |
6527 | 1301 |
if ((unsigned)(val - 'a') <= ('z' - 'a')) { |
1302 |
RETURN ( true ); |
|
1303 |
} |
|
699 | 1304 |
#ifndef OLD |
1305 |
/* iso8859 puts national lower case characters at e0 .. ff */ |
|
1306 |
if ((val >= 0xE0) && (val <= 0xFF)) { |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1307 |
RETURN(true); |
699 | 1308 |
} |
1309 |
#endif |
|
6527 | 1310 |
RETURN ( false ); |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1311 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1312 |
^ (asciivalue between:($a asciiValue) and:($z asciiValue)) |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1313 |
or:[asciivalue between:16rE0 and:16rFF] |
154 | 1314 |
! |
1315 |
||
699 | 1316 |
isPrintable |
1317 |
"return true, if the receiver is a useful printable character |
|
1318 |
(see fileBrowsers showFile:-method on how it can be used)" |
|
1 | 1319 |
|
699 | 1320 |
(asciivalue between:32 and:127) ifTrue:[^ true]. |
6398 | 1321 |
asciivalue == 12 ifTrue:[^ true]. "/ FF |
1322 |
asciivalue == 13 ifTrue:[^ true]. "/ CR |
|
1323 |
asciivalue == 9 ifTrue:[^ true]. "/ TAB |
|
1324 |
asciivalue == 10 ifTrue:[^ true]. "/ NL |
|
2840 | 1325 |
|
1326 |
(asciivalue between:16rA0 and:16rBF) ifTrue:[^ true]. "/ ISO8859 |
|
699 | 1327 |
^ self isNationalLetter |
2840 | 1328 |
|
1329 |
"Modified: 7.8.1997 / 17:05:24 / cg" |
|
1 | 1330 |
! |
1331 |
||
1332 |
isSeparator |
|
1333 |
"return true if I am a space, cr, tab, nl, or newPage" |
|
1334 |
||
1335 |
%{ /* NOCONTEXT */ |
|
1336 |
||
1337 |
REGISTER int val; |
|
1338 |
||
1133 | 1339 |
val = __intVal(__INST(asciivalue)); |
328 | 1340 |
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */ |
1341 |
if (val <= ' ') |
|
1342 |
#endif |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1343 |
if ((val == ' ') |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1344 |
|| (val == '\n') |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1345 |
|| (val == '\t') |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1346 |
|| (val == '\r') |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1347 |
|| (val == '\f')) { |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1348 |
RETURN ( true ); |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1349 |
} |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1350 |
RETURN (false); |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1351 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1352 |
^ (asciivalue == 16r20) |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1353 |
or:[asciivalue == 16r0D |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1354 |
or:[asciivalue == 16r0A |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1355 |
or:[asciivalue == 16r09 |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1356 |
or:[asciivalue == 16r0C]]]] |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1357 |
|
1 | 1358 |
! |
1359 |
||
699 | 1360 |
isUppercase |
1361 |
"return true, if I am an upper-case letter" |
|
1 | 1362 |
|
1363 |
%{ /* NOCONTEXT */ |
|
1364 |
||
1365 |
REGISTER int val; |
|
1366 |
||
1133 | 1367 |
val = __intVal(__INST(asciivalue)); |
6527 | 1368 |
if ((unsigned)(val - 'A') <= ('Z' - 'A')) { |
1369 |
RETURN ( true ); |
|
1370 |
} |
|
699 | 1371 |
#ifndef OLD |
1372 |
/* iso8859 puts national upper case characters at c0 .. df */ |
|
1373 |
if ((val >= 0xC0) && (val <= 0xDF)) { |
|
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1374 |
RETURN(true); |
314 | 1375 |
} |
699 | 1376 |
#endif |
6527 | 1377 |
RETURN ( false ); |
5423
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1378 |
%}. |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1379 |
^ (asciivalue between:($A asciiValue) and:($Z asciiValue)) |
e33decc83182
non-primitive fallBack code added
Claus Gittinger <cg@exept.de>
parents:
5407
diff
changeset
|
1380 |
or:[asciivalue between:16rC0 and:16rDF] |
1 | 1381 |
! |
1382 |
||
699 | 1383 |
isVowel |
1384 |
"return true, if I am a vowel (lower- or uppercase)" |
|
333 | 1385 |
|
6066 | 1386 |
"/ I know the code is ugly; |
1387 |
"/ better code is: |
|
1388 |
"/ 'aeiou' includes:self asLowercase |
|
1389 |
"/ or: |
|
1390 |
"/ 'aeiouAEIOU' includes:self |
|
1391 |
"/ |
|
1392 |
"/ until I have a smart compiler, I use the shorter (codewise): |
|
1393 |
||
699 | 1394 |
(self == $a) ifTrue:[^ true]. |
1395 |
(self == $e) ifTrue:[^ true]. |
|
1396 |
(self == $i) ifTrue:[^ true]. |
|
1397 |
(self == $o) ifTrue:[^ true]. |
|
1398 |
(self == $u) ifTrue:[^ true]. |
|
1399 |
(self == $A) ifTrue:[^ true]. |
|
1400 |
(self == $E) ifTrue:[^ true]. |
|
1401 |
(self == $I) ifTrue:[^ true]. |
|
1402 |
(self == $O) ifTrue:[^ true]. |
|
1403 |
(self == $U) ifTrue:[^ true]. |
|
1404 |
^ false |
|
1 | 1405 |
! ! |
699 | 1406 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1407 |
!Character methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1408 |
|
4682 | 1409 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1410 |
"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
|
1411 |
|
4682 | 1412 |
^ aRequestor traceCharacter:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1413 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1414 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4340
diff
changeset
|
1415 |
|
2124 | 1416 |
!Character class methodsFor:'documentation'! |
699 | 1417 |
|
1418 |
version |
|
7354 | 1419 |
^ '$Header: /cvs/stx/stx/libbasic/Character.st,v 1.87 2003-06-13 18:52:21 cg Exp $' |
699 | 1420 |
! ! |