/src/lib/io/basic/string_input_stream.e

http://github.com/tybor/Liberty · Specman e · 117 lines · 69 code · 20 blank · 28 comment · 0 complexity · a8888502c15a40be9e37f748a3f20961 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class STRING_INPUT_STREAM
  5. --
  6. -- An input stream where the data is read from a string.
  7. --
  8. inherit
  9. TERMINAL_INPUT_STREAM
  10. redefine
  11. valid_last_character, dispose
  12. end
  13. create {ANY}
  14. from_string
  15. feature {ANY}
  16. end_of_input: BOOLEAN
  17. do
  18. Result := offset > string.upper
  19. end
  20. is_connected: BOOLEAN
  21. must_disconnect: BOOLEAN False
  22. can_unread_character: BOOLEAN
  23. do
  24. Result := offset >= string.lower
  25. end
  26. disconnect
  27. do
  28. filter := Void
  29. is_connected := False
  30. end
  31. valid_last_character: BOOLEAN
  32. do
  33. Result := string.valid_index(offset)
  34. end
  35. feature {FILTER_INPUT_STREAM}
  36. filtered_read_character
  37. do
  38. offset := offset + 1
  39. end
  40. filtered_unread_character
  41. do
  42. offset := offset - 1
  43. end
  44. filtered_last_character: CHARACTER
  45. do
  46. Result := string.item(offset)
  47. end
  48. feature {FILTER}
  49. filtered_descriptor: INTEGER
  50. do
  51. std_error.put_string("STRING_INPUT_STREAM.filtered_descriptor has been called!%N")
  52. crash
  53. end
  54. filtered_has_descriptor: BOOLEAN False
  55. filtered_stream_pointer: POINTER
  56. do
  57. std_error.put_string("STRING_INPUT_STREAM.filtered_stream_pointer has been called!%N")
  58. crash
  59. end
  60. filtered_has_stream_pointer: BOOLEAN False
  61. feature {}
  62. dispose
  63. do
  64. -- No need to force people to disconnect such a STREAM.
  65. end
  66. from_string (a_string: ABSTRACT_STRING)
  67. require
  68. a_string /= Void
  69. do
  70. string := a_string.out
  71. offset := string.lower - 1
  72. is_connected := True
  73. end
  74. string: STRING
  75. -- where the data comes from
  76. offset: INTEGER
  77. end -- class STRING_INPUT_STREAM
  78. --
  79. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  80. --
  81. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  82. -- of this software and associated documentation files (the "Software"), to deal
  83. -- in the Software without restriction, including without limitation the rights
  84. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  85. -- copies of the Software, and to permit persons to whom the Software is
  86. -- furnished to do so, subject to the following conditions:
  87. --
  88. -- The above copyright notice and this permission notice shall be included in
  89. -- all copies or substantial portions of the Software.
  90. --
  91. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  92. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  93. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  94. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  95. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  96. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  97. -- THE SOFTWARE.