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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92171 - (show annotations)
Thu Feb 7 20:27:54 2013 UTC (6 years, 10 months ago) by manus_eiffel
File size: 8449 byte(s)
Merged from rev#747:
Added `item' to READABLE_STRING_GENERAL and proper definition in READABLE_STRING_8 descendans. So that it is easier to migrate from compatible to regular mode.

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision
svn:mergeinfo /FreeELKS/trunk/void_safe/library/kernel/readable_string_general.e:91826

  ViewVC Help
Powered by ViewVC 1.1.23