PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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