PageRenderTime 23ms CodeModel.GetById 21ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/io/filter/split_output_stream.e

http://github.com/tybor/Liberty
Specman e | 115 lines | 70 code | 15 blank | 30 comment | 1 complexity | e2fd71d5ba290c72cdb3ef6e2aa3fe3f MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4class SPLIT_OUTPUT_STREAM
  5   --
  6   -- A stream split into lines. The default line length is 76
  7   --
  8
  9inherit
 10   FILTER_OUTPUT_STREAM
 11      redefine
 12         connect_to
 13      end
 14
 15create {ANY}
 16    connect_to
 17
 18feature {ANY} -- creation
 19   Default_line_length: INTEGER 76
 20         -- This length is the default for Base64 (see http://www.faqs.org/rfcs/rfc2045)
 21
 22   Default_line_separator: STRING "%R%N"
 23
 24   line_length: INTEGER
 25         -- Length of a line
 26
 27   line_separator: STRING
 28         -- What to put at the end of a line (e.g. Quoted-Printable would set "=%R%N" here)
 29
 30   connect_to (a_stream: like stream)
 31      do
 32         Precursor(a_stream)
 33         set_line_length(Default_line_length)
 34         set_line_separator(Default_line_separator)
 35      end
 36
 37   set_line_length (a_length: like line_length)
 38      require
 39         a_length > 0
 40      do
 41         line_length := a_length
 42      ensure
 43         line_length = a_length
 44      end
 45
 46   set_line_separator (a_separator: like line_separator)
 47      require
 48         a_separator.count > 0
 49      do
 50         line_separator := a_separator
 51      ensure
 52         line_separator = a_separator
 53      end
 54
 55feature {FILTER_OUTPUT_STREAM}
 56   filtered_put_character (c: CHARACTER)
 57      local
 58         i: INTEGER
 59      do
 60         stream.filtered_put_character(c)
 61         inspect
 62            c
 63         when '%R', '%N' then
 64            current_line_length := 0
 65         else
 66            current_line_length := current_line_length + 1
 67            if current_line_length >= line_length then
 68               from
 69                  i := line_separator.lower
 70               until
 71                  i > line_separator.upper
 72               loop
 73                  stream.filtered_put_character(line_separator.item(i))
 74                  i := i + 1
 75               end
 76               current_line_length := 0
 77            end
 78         end
 79      end
 80
 81   filtered_flush
 82      do
 83         stream.filtered_flush
 84      end
 85
 86feature {}
 87   current_line_length: INTEGER
 88         -- The length of the current line
 89
 90   local_can_disconnect: BOOLEAN True
 91
 92invariant
 93   line_length > 0
 94
 95end -- SPLIT_OUTPUT_STREAM
 96--
 97-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
 98--
 99-- Permission is hereby granted, free of charge, to any person obtaining a copy
100-- of this software and associated documentation files (the "Software"), to deal
101-- in the Software without restriction, including without limitation the rights
102-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
103-- copies of the Software, and to permit persons to whom the Software is
104-- furnished to do so, subject to the following conditions:
105--
106-- The above copyright notice and this permission notice shall be included in
107-- all copies or substantial portions of the Software.
108--
109-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
115-- THE SOFTWARE.