/[eiffelstudio]/FreeELKS/tags/EiffelSoftware/Eiffel_64/library/kernel/readable_string_general.e
ViewVC logotype

Contents of /FreeELKS/tags/EiffelSoftware/Eiffel_64/library/kernel/readable_string_general.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91767 - (show annotations)
Tue Jul 28 19:42:05 2009 UTC (10 years, 4 months ago) by manus_eiffel
File size: 7800 byte(s)
Merged from rev#343 from HEAD:
  Fixed postcondition of `to_string_8' which was violated if Current was a descendant of STRING_8 (e.g. IMMUTABLE_STRING_8).

1 note
2 description: "Common ancestors to all STRING classes. Read-only interface."
3 library: "Free implementation of ELKS library"
4 copyright: "Copyright (c) 1986-2008, Eiffel Software and others"
5 license: "Eiffel Forum License v2 (see forum.txt)"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 deferred class
10 READABLE_STRING_GENERAL
11
12 inherit
13 COMPARABLE
14 export
15 {READABLE_STRING_GENERAL} copy, standard_copy, deep_copy
16 end
17
18 HASHABLE
19 export
20 {READABLE_STRING_GENERAL} copy, standard_copy, deep_copy
21 undefine
22 is_equal
23 end
24
25 STRING_HANDLER
26 export
27 {READABLE_STRING_GENERAL} copy, standard_copy, deep_copy
28 undefine
29 is_equal
30 end
31
32 feature -- Access
33
34 code (i: INTEGER): NATURAL_32
35 -- Code at position `i'
36 require
37 valid_index: valid_index (i)
38 deferred
39 end
40
41 index_of_code (c: like code; start_index: INTEGER): INTEGER
42 -- Position of first occurrence of `c' at or after `start_index';
43 -- 0 if none.
44 require
45 start_large_enough: start_index >= 1
46 start_small_enough: start_index <= count + 1
47 local
48 i, nb: INTEGER
49 do
50 nb := count
51 if start_index <= nb then
52 from
53 i := start_index
54 until
55 i > nb or else code (i) = c
56 loop
57 i := i + 1
58 end
59 if i <= nb then
60 Result := i
61 end
62 end
63 ensure
64 valid_result: Result = 0 or (start_index <= Result and Result <= count)
65 zero_if_absent: (Result = 0) = not substring (start_index, count).has_code (c)
66 found_if_present: substring (start_index, count).has_code (c) implies code (Result) = c
67 none_before: substring (start_index, count).has_code (c) implies
68 not substring (start_index, Result - 1).has_code (c)
69 end
70
71 feature -- Status report
72
73 is_immutable: BOOLEAN
74 -- Can the character sequence of `Current' be changed?
75 do
76 Result := False
77 end
78
79 count: INTEGER
80 -- Number of characters in Current
81 deferred
82 ensure
83 count_non_negative: Result >= 0
84 end
85
86 capacity: INTEGER
87 -- Number of characters allocated in Current
88 deferred
89 ensure
90 capacity_non_negative: Result >= 0
91 end
92
93 valid_index (i: INTEGER): BOOLEAN
94 -- Is `i' within the bounds of the string?
95 deferred
96 end
97
98 valid_code (v: like code): BOOLEAN
99 -- Is `v' a valid code for Current?
100 deferred
101 end
102
103 is_string_8: BOOLEAN
104 -- Is `Current' a sequence of CHARACTER_8?
105 deferred
106 end
107
108 is_string_32: BOOLEAN
109 -- Is `Current' a sequence of CHARACTER_32?
110 deferred
111 end
112
113 is_valid_as_string_8: BOOLEAN
114 -- Is `Current' convertible to a sequence of CHARACTER_8 without information loss?
115 deferred
116 end
117
118 is_empty: BOOLEAN
119 -- Is structure empty?
120 deferred
121 end
122
123 has_code (c: like code): BOOLEAN
124 -- Does string include `c'?
125 local
126 i, nb: INTEGER
127 do
128 nb := count
129 if nb > 0 then
130 from
131 i := 1
132 until
133 i > nb or else (code (i) = c)
134 loop
135 i := i + 1
136 end
137 Result := (i <= nb)
138 end
139 ensure then
140 false_if_empty: count = 0 implies not Result
141 true_if_first: count > 0 and then code (1) = c implies Result
142 recurse: (count > 0 and then code (1) /= c) implies
143 (Result = substring (2, count).has_code (c))
144 end
145
146 same_string (a_other: READABLE_STRING_GENERAL): BOOLEAN
147 -- Does `a_other' represent the same string as `Current'?
148 require
149 a_other_not_void: a_other /= Void
150 local
151 i, l_count: INTEGER
152 do
153 if a_other = Current then
154 Result := True
155 else
156 l_count := count
157 if l_count = a_other.count then
158 from
159 Result := True
160 i := 1
161 until
162 i > l_count
163 loop
164 if code (i) /= a_other.code (i) then
165 Result := False
166 i := l_count -- Jump out of the loop
167 end
168 i := i + 1
169 variant
170 increasing_index: l_count - i + 1
171 end
172 end
173 end
174 end
175
176 feature -- Conversion
177
178 frozen to_cil: SYSTEM_STRING
179 -- Create an instance of SYSTEM_STRING using characters
180 -- of Current between indices `1' and `count'.
181 require
182 is_dotnet: {PLATFORM}.is_dotnet
183 do
184 Result := dotnet_convertor.from_string_to_system_string (Current)
185 ensure
186 to_cil_not_void: Result /= Void
187 end
188
189 to_string_8: STRING_8
190 -- Convert `Current' as a STRING_8.
191 require
192 is_valid_as_string_8: is_valid_as_string_8
193 do
194 Result := as_string_8
195 ensure
196 as_string_8_not_void: Result /= Void
197 identity: (conforms_to ("") and Result = Current) or (not conforms_to ("") and Result /= Current)
198 end
199
200 as_string_8: STRING_8
201 -- Convert `Current' as a STRING_8. If a code of `Current' is
202 -- node a valid code for a STRING_8 it is replaced with the null
203 -- character.
204 local
205 i, nb: INTEGER
206 l_code: like code
207 do
208 if attached {STRING_8} Current as l_result then
209 Result := l_result
210 else
211 nb := count
212 create Result.make (nb)
213 Result.set_count (nb)
214 from
215 i := 1
216 until
217 i > nb
218 loop
219 l_code := code (i)
220 if Result.valid_code (l_code) then
221 Result.put_code (l_code, i)
222 else
223 Result.put_code (0, i)
224 end
225 i := i + 1
226 end
227 end
228 ensure
229 as_string_8_not_void: Result /= Void
230 identity: (conforms_to ("") and Result = Current) or (not conforms_to ("") and Result /= Current)
231 end
232
233 as_string_32, to_string_32: STRING_32
234 -- Convert `Current' as a STRING_32.
235 local
236 i, nb: INTEGER
237 do
238 if attached {STRING_32} Current as l_result then
239 Result := l_result
240 else
241 nb := count
242 create Result.make (nb)
243 Result.set_count (nb)
244 from
245 i := 1
246 until
247 i > nb
248 loop
249 Result.put_code (code (i), i)
250 i := i + 1
251 end
252 end
253 ensure
254 as_string_32_not_void: Result /= Void
255 identity: (conforms_to (create {STRING_32}.make_empty) and Result = Current) or (not conforms_to (create {STRING_32}.make_empty) and Result /= Current)
256 end
257
258 feature -- Duplication
259
260 substring (start_index, end_index: INTEGER): like Current
261 -- Copy of substring containing all characters at indices
262 -- between `start_index' and `end_index'
263 deferred
264 ensure
265 substring_not_void: Result /= Void
266 substring_count: Result.count = end_index - start_index + 1 or Result.count = 0
267 first_code: Result.count > 0 implies Result.code (1) = code (start_index)
268 recurse: Result.count > 0 implies
269 Result.substring (2, Result.count) ~ substring (start_index + 1, end_index)
270 end
271
272 feature {NONE} -- Assertion helper
273
274 elks_checking: BOOLEAN = False
275 -- Are ELKS checkings verified? Must be True when changing implementation of STRING_GENERAL or descendant.
276
277 feature {NONE} -- Implementation
278
279 string_searcher: STRING_SEARCHER
280 -- Facilities to search string in another string.
281 once
282 create Result.make
283 ensure
284 string_searcher_not_void: Result /= Void
285 end
286
287 c_string_provider: C_STRING
288 -- To create Eiffel strings from C string.
289 once
290 create Result.make_empty (0)
291 ensure
292 c_string_provider_not_void: Result /= Void
293 end
294
295 ctoi_convertor: STRING_TO_INTEGER_CONVERTOR
296 -- Convertor used to convert string to integer or natural
297 once
298 create Result.make
299 Result.set_leading_separators (" ")
300 Result.set_trailing_separators (" ")
301 Result.set_leading_separators_acceptable (True)
302 Result.set_trailing_separators_acceptable (True)
303 ensure
304 ctoi_convertor_not_void: Result /= Void
305 end
306
307 ctor_convertor: STRING_TO_REAL_CONVERTOR
308 -- Convertor used to convert string to real or double
309 once
310 create Result.make
311 Result.set_leading_separators (" ")
312 Result.set_trailing_separators (" ")
313 Result.set_leading_separators_acceptable (True)
314 Result.set_trailing_separators_acceptable (True)
315 ensure
316 ctor_convertor_not_void: Result /= Void
317 end
318
319 dotnet_convertor: SYSTEM_STRING_FACTORY
320 -- Convertor used to convert from and to SYSTEM_STRING.
321 once
322 create Result
323 ensure
324 dotnet_convertor_not_void: Result /= Void
325 end
326
327 internal_hash_code: INTEGER
328 -- Cache for `hash_code'
329
330 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23