PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/string/internal/iterator_on_rope.e

http://github.com/tybor/Liberty
Specman e | 94 lines | 54 code | 13 blank | 27 comment | 2 complexity | b04db3e32433605584049f069419478d MD5 | raw file
 1-- This file is part of a Liberty Eiffel library.
 2-- See the full copyright at the end.
 3--
 4class ITERATOR_ON_ROPE
 5   -- Please do not use this class directly. Look at `ITERATOR'.
 6
 7inherit
 8   ITERATOR[CHARACTER]
 9
10create {ANY}
11   make
12
13feature {}
14   root: ROPE
15         -- The beginning of the rope to be traversed.
16
17   right_visited: BOOLEAN
18         -- Has `right' been iterated onto?
19
20   iter: ITERATOR[CHARACTER]
21         -- Current position on `piece'.
22
23feature {ANY}
24   make (r: like root)
25      require
26         r /= Void
27      do
28         root := r
29      ensure
30         root = r
31      end
32
33   start
34      do
35         right_visited := False
36         iter := root.left.new_iterator
37         iter.start
38      ensure then
39         iter /= Void
40      end
41
42   is_off: BOOLEAN
43      do
44         Result := iter = Void
45      end
46
47   item: CHARACTER
48      do
49         Result := iter.item
50      end
51
52   next
53      do
54         iter.next
55         if iter.is_off then -- switch to the next piece of rope
56            if right_visited then
57               iter := Void
58            else
59               right_visited := True
60               iter := root.right.new_iterator
61               iter.start
62            end
63         end
64      end
65
66feature {ANY}
67   iterable_generation: INTEGER
68      do
69         Result := root.generation
70      end
71
72   generation: INTEGER
73
74end -- class ITERATOR_ON_ROPE
75--
76-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
77--
78-- Permission is hereby granted, free of charge, to any person obtaining a copy
79-- of this software and associated documentation files (the "Software"), to deal
80-- in the Software without restriction, including without limitation the rights
81-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
82-- copies of the Software, and to permit persons to whom the Software is
83-- furnished to do so, subject to the following conditions:
84--
85-- The above copyright notice and this permission notice shall be included in
86-- all copies or substantial portions of the Software.
87--
88-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
89-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
90-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
91-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
92-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
93-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
94-- THE SOFTWARE.