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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 3 months ago) by manus_eiffel
File size: 7310 byte(s)
Initial revision

1 indexing
2
3 status: "See notice at end of class"
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class SEQ_STRING inherit
8
9 STRING
10 rename
11 precede as string_precede,
12 prepend as string_prepend,
13 mirrored as string_mirrored,
14 mirror as string_mirror,
15 share as string_share,
16 wipe_out as string_wipe_out
17 export
18 {ANY}
19 linear_representation
20 undefine
21 linear_representation
22 redefine
23 has, prune
24 end
25
26 SEQUENCE [CHARACTER]
27 rename
28 append as seq_append,
29 item as current_item,
30 index_of as index_of_occurrence,
31 put as sequence_put,
32 remove as remove_current_item
33 export
34 {NONE}
35 sequence_put, seq_append
36 undefine
37 occurrences, out, copy, is_equal, prune_all,
38 changeable_comparison_criterion
39 redefine
40 has, index_of_occurrence, prune
41 select
42 wipe_out, sequence_put
43 end
44
45 create
46
47 make
48
49 feature -- Access
50
51 search_after (c: CHARACTER) is
52 -- Move cursor to first position
53 -- (at or after current cursor position)
54 -- where `current_item' and `c' are identical.
55 do
56 if not off then
57 index := index_of (c, index)
58 if index = 0 then
59 index := count + 1
60 end
61 end
62 end
63
64 search_before (c: CHARACTER) is
65 -- Move cursor to greatest position at or before cursor
66 -- where `current_item' and `c' are identical;
67 -- go before if unsuccessful.
68 local
69 str: like Current
70 do
71 str := mirrored
72 if not str.off then
73 index := count + 1 - str.index_of (c, str.index)
74 if index = count + 1 then
75 index := 0
76 end
77 end
78 end
79
80 search_string_after (s: STRING; fuzzy: INTEGER) is
81 -- Move cursor to first position
82 -- (at or after cursor position) where `substring
83 -- (index, index + s.count)' and `s' are identical.
84 -- Go after if unsuccessful.
85 -- The 'fuzzy' parameter is the maximum allowed number
86 -- of mismatches within the pattern. A 0 means an exact match.
87 do
88 if not off then
89 index := fuzzy_index (s, index, fuzzy)
90 if index = 0 then
91 index := count + 1
92 end
93 end
94 end
95
96 search_string_before (s: STRING; fuzzy: INTEGER) is
97 -- Move cursor to first position
98 -- (at or before cursor position) where `substring
99 -- (index, index + s.count)' and `s' are identical.
100 -- Go before if unsuccessful.
101 -- The 'fuzzy' parameter is the maximum allowed number
102 -- of mismatches within the pattern. A 0 means an exact match.
103 local
104 str_mirrored: like Current
105 s_mirrored: STRING
106 do
107 if not off then
108 str_mirrored := mirrored
109 s_mirrored := s.mirrored
110 index := count - str_mirrored.fuzzy_index (s_mirrored, count - index, fuzzy) + 1
111 if index = count + 1 then
112 index := 0
113 else
114 index := index - s.count + 1
115 end
116 end
117 end
118
119 current_item: CHARACTER is
120 -- Current item
121 do
122 Result := item (index)
123 end
124
125 index: INTEGER
126 -- Index of `current_item', if valid
127 -- Valid values are between 1 and `count' (if `count' > 0).
128
129 index_of_occurrence (c: CHARACTER; i: INTEGER): INTEGER is
130 -- Index of `i'-th occurrence of `c'.
131 -- 0 if none.
132 local
133 occur: INTEGER
134 do
135 if not is_empty then
136 from
137 Result := index_of (c, 1)
138 if Result /= 0 then
139 occur := 1
140 end
141 until
142 (Result = 0) or else (occur = i)
143 loop
144 if Result /= count then
145 Result := index_of (c, Result + 1)
146 if Result /= 0 then
147 occur := occur + 1
148 end
149 else
150 Result := 0
151 end
152 end
153 end
154 ensure then
155 Index_value: (Result = 0) or item (Result) = c
156 end
157
158
159
160 has (c: CHARACTER): BOOLEAN is
161 -- Does string include `c'?
162 do
163 if not is_empty then
164 Result := (index_of (c, 1) /= 0)
165 end
166 end
167
168 feature -- Status report
169
170 before: BOOLEAN is
171 -- Is there no valid cursor position to the left of cursor?
172 do
173 Result := index < 1
174 end
175
176 after: BOOLEAN is
177 -- Is there no valid cursor position to the right of cursor?
178 do
179 Result := index > count
180 end
181
182 feature -- Cursor movement
183
184 start is
185 -- Move to first position.
186 do
187 index := 1
188 end
189
190 finish is
191 -- Move to last position.
192 do
193 index := count
194 end
195
196 back is
197 -- Move to previous position.
198 do
199 index := index - 1
200 end
201
202 forth is
203 -- Move to next position.
204 do
205 index := index + 1
206 end
207
208 feature -- Element change
209
210 replace (c: CHARACTER) is
211 -- Replace current item by `c'.
212 do
213 put (c, index)
214 end
215
216 share (other: like Current) is
217 -- Make string share the text of `other'.
218 require
219 argument_not_void: other /= Void
220 do
221 string_share (other)
222 index := other.index
223 ensure
224 shared_index: other.index = index
225 end
226
227 precede (c: CHARACTER) is
228 -- Add `c' at front.
229 do
230 string_precede (c)
231 index := index + 1
232 ensure
233 new_index: index = old index + 1
234 end
235
236 prepend (s: STRING) is
237 -- Prepend a copy of `s' at front.
238 require
239 argument_not_void: s /= Void
240 do
241 string_prepend (s)
242 index := index + s.count
243 ensure
244 new_index: index = old index + s.count
245 end
246
247 feature -- Removal
248
249 prune (c: CHARACTER) is
250 -- Remove first occurrence of `c'.
251 local
252 i: INTEGER
253 do
254 if count /= 0 then
255 i := index_of (c, 1)
256 if i /= 0 then
257 remove (i)
258 end
259 end
260 end
261
262 remove_current_item is
263 -- Remove current item.
264 do
265 remove (index)
266 end
267
268 wipe_out is
269 -- Clear out all characters.
270 do
271 string_wipe_out
272 index := 0
273 end
274
275 feature -- Duplication
276
277 mirrored: like Current is
278 -- Current string read from right to left.
279 -- The result string has the same `capacity' and the
280 -- same current position (i.e. the cursor is pointing
281 -- at the same item)
282 do
283 Result := string_mirrored
284 if not after then
285 from
286 Result.start
287 until
288 Result.index = count - index + 1
289 loop
290 Result.forth
291 end
292 end
293 ensure
294 mirrored_index: Result.index = count - index + 1
295 same_count: Result.count = count
296 -- reverse_entries:
297 -- for all `i: 1..count, Result.item (i) = item (count + 1 - i)'
298 end
299
300 mirror is
301 -- Reverse the characters order.
302 -- "Hello world" -> "dlrow olleH".
303 -- The current position will be on the same item
304 -- as before.
305 do
306 string_mirror
307 index := count + 1 - index
308 ensure
309 same_count: count = old count
310 mirrored_index: index = count - old index + 1
311 -- reverse_entries:
312 -- for all `i: 1..count, item (i) = old item (count + 1 - i)'
313 end
314
315 feature {NONE} -- Inapplicable
316
317 go_to (r: CURSOR) is
318 -- Go to position marked `r'.
319 do
320 end
321
322 indexing
323
324 library: "[
325 EiffelBase: Library of reusable components for Eiffel.
326 ]"
327
328 status: "[
329 Copyright 1986-2001 Interactive Software Engineering (ISE).
330 For ISE customers the original versions are an ISE product
331 covered by the ISE Eiffel license and support agreements.
332 ]"
333
334 license: "[
335 EiffelBase may now be used by anyone as FREE SOFTWARE to
336 develop any product, public-domain or commercial, without
337 payment to ISE, under the terms of the ISE Free Eiffel Library
338 License (IFELL) at http://eiffel.com/products/base/license.html.
339 ]"
340
341 source: "[
342 Interactive Software Engineering Inc.
343 ISE Building
344 360 Storke Road, Goleta, CA 93117 USA
345 Telephone 805-685-1006, Fax 805-685-6869
346 Electronic mail <info@eiffel.com>
347 Customer support http://support.eiffel.com
348 ]"
349
350 info: "[
351 For latest info see award-winning pages: http://eiffel.com
352 ]"
353
354 end -- class SEQ_STRING
355
356

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23