/[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 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 5460 byte(s)
Initial revision

1 indexing
2
3 description:
4 "References to objects containing a character value"
5
6 status: "See notice at end of class"
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class CHARACTER_REF inherit
11
12 COMPARABLE
13 redefine
14 out, is_equal
15 end
16
17 HASHABLE
18 redefine
19 is_hashable, out, is_equal
20 end
21
22 feature -- Access
23
24 item: CHARACTER
25 -- Character value
26
27 code: INTEGER is
28 -- Associated integer value
29 do
30 Result := chcode (item)
31 end
32
33 hash_code: INTEGER is
34 -- Hash code value
35 do
36 Result := code
37 end
38
39 Min_value: INTEGER is 0
40 Max_value: INTEGER is 255
41 -- Bounds for integer representation of characters (ASCII)
42
43 feature -- Status report
44
45 is_hashable: BOOLEAN is
46 -- May current object be hashed?
47 -- (True if it is not its type's default.)
48 do
49 Result := item /= '%U'
50 end
51
52 feature -- Comparison
53
54 infix "<" (other: like Current): BOOLEAN is
55 -- Is `other' greater than current character?
56 do
57 Result := item < other.item
58 ensure then
59 definition: Result = (code < other.code)
60 end
61
62 is_equal (other: like Current): BOOLEAN is
63 -- Is `other' attached to an object of the same type
64 -- as current object and identical to it?
65 do
66 Result := other.item = item
67 end
68
69 feature -- Basic routines
70
71 infix "+" (incr: INTEGER): CHARACTER is
72 -- Add `incr' to the code of `item'
73 require
74 valid_increment: (item.code + incr).is_valid_character_code
75 do
76 Result := chconv (chcode (item) + incr)
77 ensure
78 valid_result: Result |-| item = incr
79 end
80
81 infix "-" (decr: INTEGER): CHARACTER is
82 -- Subtract `decr' to the code of `item'
83 require
84 valid_decrement: (item.code - decr).is_valid_character_code
85 do
86 Result := chconv (chcode (item) - decr)
87 ensure
88 valid_result: item |-| Result = decr
89 end
90
91 infix "|-|" (other: CHARACTER): INTEGER is
92 -- Difference between the codes of `item' and `other'
93 do
94 Result := chcode (item) - chcode (other)
95 ensure
96 valid_result: other + Result = item
97 end
98
99 next: CHARACTER is
100 -- Next character
101 require
102 valid_character: (item.code + 1).is_valid_character_code
103 do
104 Result := item + 1
105 ensure
106 valid_result: Result |-| item = 1
107 end
108
109 previous: CHARACTER is
110 -- Previous character
111 require
112 valid_character: (item.code - 1).is_valid_character_code
113 do
114 Result := item - 1
115 ensure
116 valid_result: Result |-| item = -1
117 end
118
119 feature -- Element change
120
121 set_item (c: CHARACTER) is
122 -- Make `c' the `item' value.
123 do
124 item := c
125 end
126
127 feature -- Output
128
129 out: STRING is
130 -- Printable representation of character
131 do
132 Result := c_outc (item)
133 end
134
135 feature {NONE} -- Initialization
136
137 make_from_reference (v: CHARACTER_REF) is
138 -- Initialize `Current' with `v.item'.
139 require
140 v_not_void: V /= Void
141 do
142 item := v.item
143 ensure
144 item_set: item = v.item
145 end
146
147 feature -- Conversion
148
149 to_reference: CHARACTER_REF is
150 -- Associated reference of Current
151 do
152 create Result
153 Result.set_item (item)
154 ensure
155 to_reference_not_void: Result /= Void
156 end
157
158 as_upper, upper: CHARACTER is
159 -- Uppercase value of `item'
160 -- Returns `item' if not `is_lower'
161 do
162 Result := chupper (item)
163 end
164
165 as_lower, lower: CHARACTER is
166 -- Lowercase value of `item'
167 -- Returns `item' if not `is_upper'
168 do
169 Result := chlower (item)
170 end
171
172 feature -- Status report
173
174 is_lower: BOOLEAN is
175 -- Is `item' lowercase?
176 do
177 Result := chis_lower (item)
178 end
179
180 is_upper: BOOLEAN is
181 -- Is `item' uppercase?
182 do
183 Result := chis_upper (item)
184 end
185
186 is_digit: BOOLEAN is
187 -- Is `item' a digit?
188 -- A digit is one of 0123456789
189 do
190 Result := chis_digit (item)
191 end
192
193 is_alpha: BOOLEAN is
194 -- Is `item' alphabetic?
195 -- Alphabetic is `is_upper' or `is_lower'
196 do
197 Result := chis_alpha (item)
198 end
199
200 feature {NONE} -- Implementation
201
202 chcode (c: like item): INTEGER is
203 -- Associated integer value
204 external
205 "built_in"
206 end
207
208 chconv (i: INTEGER): CHARACTER is
209 -- Character associated with integer value `i'
210 external
211 "built_in"
212 end
213
214 c_outc (c: CHARACTER): STRING is
215 -- Printable representation of character
216 external
217 "built_in"
218 end
219
220 chupper (c: CHARACTER): CHARACTER is
221 external
222 "built_in"
223 end
224
225 chlower (c: CHARACTER): CHARACTER is
226 external
227 "built_in"
228 end
229
230 chis_lower (c: CHARACTER): BOOLEAN is
231 external
232 "built_in"
233 end
234
235 chis_upper (c: CHARACTER): BOOLEAN is
236 external
237 "built_in"
238 end
239
240 chis_digit (c: CHARACTER): BOOLEAN is
241 external
242 "built_in"
243 end
244
245 chis_alpha (c: CHARACTER): BOOLEAN is
246 external
247 "built_in"
248 end
249
250 indexing
251
252 library: "[
253 EiffelBase: Library of reusable components for Eiffel.
254 ]"
255
256 status: "[
257 Copyright 1986-2001 Interactive Software Engineering (ISE).
258 For ISE customers the original versions are an ISE product
259 covered by the ISE Eiffel license and support agreements.
260 ]"
261
262 license: "[
263 EiffelBase may now be used by anyone as FREE SOFTWARE to
264 develop any product, public-domain or commercial, without
265 payment to ISE, under the terms of the ISE Free Eiffel Library
266 License (IFELL) at http://eiffel.com/products/base/license.html.
267 ]"
268
269 source: "[
270 Interactive Software Engineering Inc.
271 ISE Building
272 360 Storke Road, Goleta, CA 93117 USA
273 Telephone 805-685-1006, Fax 805-685-6869
274 Electronic mail <info@eiffel.com>
275 Customer support http://support.eiffel.com
276 ]"
277
278 info: "[
279 For latest info see award-winning pages: http://eiffel.com
280 ]"
281
282 end -- class CHARACTER_REF
283
284
285

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23