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