/src/lib/io/basic/string_output_stream.e

http://github.com/tybor/Liberty · Specman e · 144 lines · 88 code · 22 blank · 34 comment · 0 complexity · 88527a0248eaff261e0ee2054b28db81 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_OUTPUT_STREAM
  5. --
  6. -- An output stream where data is written to a string buffer.
  7. --
  8. inherit
  9. TERMINAL_OUTPUT_STREAM
  10. redefine put_abstract_string, dispose
  11. end
  12. create {ANY}
  13. make, connect_to
  14. feature {ANY}
  15. to_string: STRING
  16. -- A copy of the internal buffer. If you don't want memory consumption, see `append_in'.
  17. do
  18. Result := string.twin
  19. end
  20. append_in (a_string: STRING)
  21. -- Append the contents of the internal buffer to the given string.
  22. require
  23. a_string /= Void
  24. do
  25. a_string.append(string)
  26. end
  27. write_to (output: OUTPUT_STREAM)
  28. -- Write the contents of the internal buffer to the given output stream.
  29. require
  30. output.is_connected
  31. do
  32. output.put_string(string)
  33. end
  34. count: INTEGER
  35. -- The size of the internal buffer
  36. do
  37. Result := string.count
  38. end
  39. is_connected: BOOLEAN
  40. disconnect
  41. do
  42. filter := Void
  43. is_connected := False
  44. end
  45. clear
  46. -- Remove all stored characters
  47. do
  48. string.clear_count
  49. ensure
  50. string.is_empty
  51. end
  52. feature {FILTER_OUTPUT_STREAM}
  53. filtered_put_character (c: CHARACTER)
  54. do
  55. string.extend(c)
  56. end
  57. filtered_flush
  58. do
  59. -- nothing to do
  60. end
  61. feature {ABSTRACT_STRING}
  62. put_abstract_string (s: ABSTRACT_STRING)
  63. do
  64. string.append(s)
  65. end
  66. feature {FILTER}
  67. filtered_descriptor: INTEGER
  68. do
  69. std_error.put_string("STRING_OUTPUT_STREAM.filtered_descriptor has been called!%N")
  70. crash
  71. end
  72. filtered_has_descriptor: BOOLEAN False
  73. filtered_stream_pointer: POINTER
  74. do
  75. std_error.put_string("STRING_OUTPUT_STREAM.filtered_stream_pointer has been called!%N")
  76. crash
  77. end
  78. filtered_has_stream_pointer: BOOLEAN False
  79. feature {}
  80. make
  81. do
  82. string := ""
  83. is_connected := True
  84. end
  85. connect_to (a_string: like string)
  86. require
  87. not a_string.immutable
  88. do
  89. string := a_string
  90. is_connected := True
  91. ensure
  92. string = a_string
  93. end
  94. string: STRING
  95. -- where the characters go to
  96. dispose
  97. do
  98. -- No need to force people to disconnect such a STREAM.
  99. end
  100. invariant
  101. not string.immutable
  102. end -- class STRING_OUTPUT_STREAM
  103. --
  104. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  105. --
  106. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  107. -- of this software and associated documentation files (the "Software"), to deal
  108. -- in the Software without restriction, including without limitation the rights
  109. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  110. -- copies of the Software, and to permit persons to whom the Software is
  111. -- furnished to do so, subject to the following conditions:
  112. --
  113. -- The above copyright notice and this permission notice shall be included in
  114. -- all copies or substantial portions of the Software.
  115. --
  116. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  117. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  118. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  119. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  120. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  121. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  122. -- THE SOFTWARE.