/[eiffelstudio]/FreeELKS/trunk/library/kernel/character_ref.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/character_ref.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91446 - (show annotations)
Mon Nov 14 10:53:30 2005 UTC (14 years, 2 months ago) by ericb
File size: 11490 byte(s)
Made it follow the current implementation in ISE.
Added built-in features.

1 indexing
2 description: "References to objects containing a character value"
3 library: "Free implementation of ELKS library"
4 copyright: "Copyright (c) 1986-2004, Eiffel Software and others"
5 license: "Eiffel Forum License v2 (see forum.txt)"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class CHARACTER_REF inherit
10
11 COMPARABLE
12 redefine
13 out, is_equal
14 end
15
16 HASHABLE
17 redefine
18 is_hashable, out, is_equal
19 end
20
21 REFACTORING_HELPER
22 redefine
23 out, is_equal
24 end
25
26 feature -- Access
27
28 item: CHARACTER is
29 -- Character value
30 external
31 "built_in"
32 end
33
34 code: INTEGER is
35 -- Associated integer value
36 do
37 Result := item.code
38 end
39
40 hash_code: INTEGER is
41 -- Hash code value
42 do
43 Result := code
44 end
45
46 Min_value: INTEGER is 0
47 Max_value: INTEGER is 255
48 -- Bounds for integer representation of characters (ASCII)
49
50 feature -- Status report
51
52 is_hashable: BOOLEAN is
53 -- May current object be hashed?
54 -- (True if it is not its type's default.)
55 do
56 Result := item /= '%U'
57 end
58
59 feature -- Comparison
60
61 infix "<" (other: like Current): BOOLEAN is
62 -- Is `other' greater than current character?
63 do
64 Result := code < other.code
65 ensure then
66 definition: Result = (code < other.code)
67 end
68
69 is_equal (other: like Current): BOOLEAN is
70 -- Is `other' attached to an object of the same type
71 -- as current object and identical to it?
72 do
73 Result := other.item = item
74 end
75
76 feature -- Basic routines
77
78 infix "+" (incr: INTEGER): CHARACTER is
79 -- Add `incr' to the code of `item'
80 require
81 valid_increment: (item.code + incr).is_valid_character_code
82 do
83 Result := (item.code + incr).to_character
84 ensure
85 valid_result: Result |-| item = incr
86 end
87
88 infix "-" (decr: INTEGER): CHARACTER is
89 -- Subtract `decr' to the code of `item'
90 require
91 valid_decrement: (item.code - decr).is_valid_character_code
92 do
93 Result := (item.code - decr).to_character
94 ensure
95 valid_result: item |-| Result = decr
96 end
97
98 infix "|-|" (other: CHARACTER): INTEGER is
99 -- Difference between the codes of `item' and `other'
100 do
101 Result := item.code - other.code
102 ensure
103 valid_result: other + Result = item
104 end
105
106 next: CHARACTER is
107 -- Next character
108 require
109 valid_character: (item.code + 1).is_valid_character_code
110 do
111 Result := item + 1
112 ensure
113 valid_result: Result |-| item = 1
114 end
115
116 previous: CHARACTER is
117 -- Previous character
118 require
119 valid_character: (item.code - 1).is_valid_character_code
120 do
121 Result := item - 1
122 ensure
123 valid_result: Result |-| item = -1
124 end
125
126 feature -- Element change
127
128 set_item (c: CHARACTER) is
129 -- Make `c' the `item' value.
130 external
131 "built_in"
132 end
133
134 feature -- Output
135
136 out: STRING is
137 -- Printable representation of character
138 do
139 create Result.make (1)
140 Result.append_character (item)
141 end
142
143 feature {NONE} -- Initialization
144
145 make_from_reference (v: CHARACTER_REF) is
146 -- Initialize `Current' with `v.item'.
147 require
148 v_not_void: v /= Void
149 do
150 set_item (v)
151 ensure
152 item_set: item = v.item
153 end
154
155 feature -- Conversion
156
157 to_reference: CHARACTER_REF is
158 -- Associated reference of Current
159 do
160 create Result
161 Result.set_item (item)
162 ensure
163 to_reference_not_void: Result /= Void
164 end
165
166 as_upper, upper: CHARACTER is
167 -- Uppercase value of `item'
168 -- Returns `item' if not `is_lower'
169 do
170 if is_lower then
171 Result := (item.code - ('a').code + ('A').code).to_character
172 else
173 Result := item
174 end
175 end
176
177 as_lower, lower: CHARACTER is
178 -- Lowercase value of `item'
179 -- Returns `item' if not `is_upper'
180 do
181 if is_upper then
182 Result := (item.code - ('A').code + ('a').code).to_character
183 else
184 Result := item
185 end
186 end
187
188 feature -- Status report
189
190 is_alpha: BOOLEAN is
191 -- Is `item' alphabetic?
192 -- Alphabetic is `is_upper' or `is_lower'
193 do
194 Result := (character_types (item.code) & (is_upper_flag | is_lower_flag)) > 0
195 end
196
197 is_upper: BOOLEAN is
198 -- Is `item' uppercase?
199 do
200 Result := (character_types (item.code) & is_upper_flag) > 0
201 end
202
203 is_lower: BOOLEAN is
204 -- Is `item' lowercase?
205 do
206 Result := (character_types (item.code) & is_lower_flag) > 0
207 end
208
209 is_digit: BOOLEAN is
210 -- Is `item' a digit?
211 -- A digit is one of 0123456789
212 do
213 Result := (character_types (item.code) & is_digit_flag) > 0
214 end
215
216 is_hexa_digit: BOOLEAN is
217 -- Is `item' an hexadecimal digit?
218 -- A digit is one of 0123456789ABCDEFabcedf
219 do
220 Result := (character_types (item.code) & (is_hexa_digit_flag | is_digit_flag)) > 0
221 end
222
223 is_space: BOOLEAN is
224 -- Is `item' a white space?
225 do
226 Result := (character_types (item.code) & is_white_space_flag) > 0
227 end
228
229 is_punctuation: BOOLEAN is
230 -- Is `item' a punctuation?
231 do
232 Result := (character_types (item.code) & is_punctuation_flag) > 0
233 end
234
235 is_alpha_numeric: BOOLEAN is
236 -- Is `item' alphabetic or a digit?
237 do
238 Result := (character_types (item.code) & (is_upper_flag | is_lower_flag | is_digit_flag)) > 0
239 end
240
241 is_printable: BOOLEAN is
242 -- Is `item' a printable character including space?
243 do
244 Result := (character_types (item.code) &
245 (is_upper_flag | is_lower_flag | is_digit_flag | is_punctuation_flag | is_space_flag)) > 0
246 end
247
248 is_graph: BOOLEAN is
249 -- Is `item' a printable character except space?
250 do
251 Result := (character_types (item.code) &
252 (is_upper_flag | is_lower_flag | is_digit_flag | is_punctuation_flag)) > 0
253 end
254
255 is_control: BOOLEAN is
256 -- Is `item' a control character?
257 do
258 Result := (character_types (item.code) & is_control_flag) > 0
259 end
260
261 feature {NONE} -- Implementation
262
263 character_types (a_code: INTEGER): NATURAL_8 is
264 -- Associated type for character of code `a_code'.
265 do
266 -- For character whose code is above 256, it is as if
267 -- we had no information about it.
268 if a_code < 256 then
269 Result := internal_character_types.item (a_code)
270 end
271 end
272
273 internal_character_types: SPECIAL [NATURAL_8] is
274 -- Array which stores the various type for the ASCII characters.
275 once
276 create Result.make (256)
277 Result.put (is_control_flag, 0)
278 Result.put (is_control_flag, 1)
279 Result.put (is_control_flag, 2)
280 Result.put (is_control_flag, 3)
281 Result.put (is_control_flag, 4)
282 Result.put (is_control_flag, 5)
283 Result.put (is_control_flag, 6)
284 Result.put (is_control_flag, 7)
285 Result.put (is_control_flag, 8)
286 Result.put (is_control_flag | is_white_space_flag, 9)
287 Result.put (is_control_flag | is_white_space_flag, 10)
288 Result.put (is_control_flag | is_white_space_flag, 11)
289 Result.put (is_control_flag | is_white_space_flag, 12)
290 Result.put (is_control_flag | is_white_space_flag, 13)
291 Result.put (is_control_flag, 14)
292 Result.put (is_control_flag, 15)
293 Result.put (is_control_flag, 16)
294 Result.put (is_control_flag, 17)
295 Result.put (is_control_flag, 18)
296 Result.put (is_control_flag, 19)
297 Result.put (is_control_flag, 20)
298 Result.put (is_control_flag, 21)
299 Result.put (is_control_flag, 22)
300 Result.put (is_control_flag, 23)
301 Result.put (is_control_flag, 24)
302 Result.put (is_control_flag, 25)
303 Result.put (is_control_flag, 26)
304 Result.put (is_control_flag, 27)
305 Result.put (is_control_flag, 28)
306 Result.put (is_control_flag, 29)
307 Result.put (is_control_flag, 30)
308 Result.put (is_control_flag, 31)
309 Result.put (is_white_space_flag | is_space_flag, 32)
310 Result.put (is_punctuation_flag, 33)
311 Result.put (is_punctuation_flag, 34)
312 Result.put (is_punctuation_flag, 35)
313 Result.put (is_punctuation_flag, 36)
314 Result.put (is_punctuation_flag, 37)
315 Result.put (is_punctuation_flag, 38)
316 Result.put (is_punctuation_flag, 39)
317 Result.put (is_punctuation_flag, 40)
318 Result.put (is_punctuation_flag, 41)
319 Result.put (is_punctuation_flag, 42)
320 Result.put (is_punctuation_flag, 43)
321 Result.put (is_punctuation_flag, 44)
322 Result.put (is_punctuation_flag, 45)
323 Result.put (is_punctuation_flag, 46)
324 Result.put (is_punctuation_flag, 47)
325 Result.put (is_digit_flag, 48)
326 Result.put (is_digit_flag, 49)
327 Result.put (is_digit_flag, 50)
328 Result.put (is_digit_flag, 51)
329 Result.put (is_digit_flag, 52)
330 Result.put (is_digit_flag, 53)
331 Result.put (is_digit_flag, 54)
332 Result.put (is_digit_flag, 55)
333 Result.put (is_digit_flag, 56)
334 Result.put (is_digit_flag, 57)
335 Result.put (is_punctuation_flag, 58)
336 Result.put (is_punctuation_flag, 59)
337 Result.put (is_punctuation_flag, 60)
338 Result.put (is_punctuation_flag, 61)
339 Result.put (is_punctuation_flag, 62)
340 Result.put (is_punctuation_flag, 63)
341 Result.put (is_punctuation_flag, 64)
342 Result.put (is_upper_flag | is_hexa_digit_flag, 65)
343 Result.put (is_upper_flag | is_hexa_digit_flag, 66)
344 Result.put (is_upper_flag | is_hexa_digit_flag, 67)
345 Result.put (is_upper_flag | is_hexa_digit_flag, 68)
346 Result.put (is_upper_flag | is_hexa_digit_flag, 69)
347 Result.put (is_upper_flag | is_hexa_digit_flag, 70)
348 Result.put (is_upper_flag, 71)
349 Result.put (is_upper_flag, 72)
350 Result.put (is_upper_flag, 73)
351 Result.put (is_upper_flag, 74)
352 Result.put (is_upper_flag, 75)
353 Result.put (is_upper_flag, 76)
354 Result.put (is_upper_flag, 77)
355 Result.put (is_upper_flag, 78)
356 Result.put (is_upper_flag, 79)
357 Result.put (is_upper_flag, 80)
358 Result.put (is_upper_flag, 81)
359 Result.put (is_upper_flag, 82)
360 Result.put (is_upper_flag, 83)
361 Result.put (is_upper_flag, 84)
362 Result.put (is_upper_flag, 85)
363 Result.put (is_upper_flag, 86)
364 Result.put (is_upper_flag, 87)
365 Result.put (is_upper_flag, 88)
366 Result.put (is_upper_flag, 89)
367 Result.put (is_upper_flag, 90)
368 Result.put (is_punctuation_flag, 91)
369 Result.put (is_punctuation_flag, 92)
370 Result.put (is_punctuation_flag, 93)
371 Result.put (is_punctuation_flag, 94)
372 Result.put (is_punctuation_flag, 95)
373 Result.put (is_punctuation_flag, 96)
374 Result.put (is_lower_flag | is_hexa_digit_flag, 97)
375 Result.put (is_lower_flag | is_hexa_digit_flag, 98)
376 Result.put (is_lower_flag | is_hexa_digit_flag, 99)
377 Result.put (is_lower_flag | is_hexa_digit_flag, 100)
378 Result.put (is_lower_flag | is_hexa_digit_flag, 101)
379 Result.put (is_lower_flag | is_hexa_digit_flag, 102)
380 Result.put (is_lower_flag, 103)
381 Result.put (is_lower_flag, 104)
382 Result.put (is_lower_flag, 105)
383 Result.put (is_lower_flag, 106)
384 Result.put (is_lower_flag, 107)
385 Result.put (is_lower_flag, 108)
386 Result.put (is_lower_flag, 109)
387 Result.put (is_lower_flag, 110)
388 Result.put (is_lower_flag, 111)
389 Result.put (is_lower_flag, 112)
390 Result.put (is_lower_flag, 113)
391 Result.put (is_lower_flag, 114)
392 Result.put (is_lower_flag, 115)
393 Result.put (is_lower_flag, 116)
394 Result.put (is_lower_flag, 117)
395 Result.put (is_lower_flag, 118)
396 Result.put (is_lower_flag, 119)
397 Result.put (is_lower_flag, 120)
398 Result.put (is_lower_flag, 121)
399 Result.put (is_lower_flag, 122)
400 Result.put (is_punctuation_flag, 123)
401 Result.put (is_punctuation_flag, 124)
402 Result.put (is_punctuation_flag, 125)
403 Result.put (is_punctuation_flag, 126)
404 Result.put (is_control_flag, 127)
405 end
406
407 is_upper_flag: NATURAL_8 is {NATURAL_8} 0x01
408
409 is_lower_flag: NATURAL_8 is {NATURAL_8} 0x02
410
411 is_digit_flag: NATURAL_8 is {NATURAL_8} 0x04
412
413 is_white_space_flag: NATURAL_8 is {NATURAL_8} 0x08
414
415 is_punctuation_flag: NATURAL_8 is {NATURAL_8} 0x10
416
417 is_control_flag: NATURAL_8 is {NATURAL_8} 0x20
418
419 is_hexa_digit_flag: NATURAL_8 is {NATURAL_8} 0x40
420
421 is_space_flag: NATURAL_8 is {NATURAL_8} 0x80;
422
423 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23