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