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

Annotation of /FreeELKS/trunk/library/kernel/character_8_ref.e

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23