Improved WGI_INPUT_STREAM.append_to_file (f: FILE; nb: INTEGER)

This commit is contained in:
2013-05-28 15:04:50 +02:00
parent 401bbc657a
commit 5b6c257fae

View File

@@ -137,26 +137,34 @@ feature -- Input
a_file_is_open_write: a_file.is_open_write a_file_is_open_write: a_file.is_open_write
nb_large_enough: nb > 0 nb_large_enough: nb > 0
local local
s: like last_string
i, end_pos: INTEGER i, end_pos: INTEGER
l_count: INTEGER l_count: INTEGER
n: INTEGER
l_remaining: INTEGER
do do
from from
i := a_string.count + 1 n := nb.min (2_048)
end_pos := i + nb - 1 l_remaining := nb - n
until until
i > end_pos l_remaining = 0 or n = 0
loop loop
read_character read_string (n)
a_file.put_character (last_character) s := last_string
l_count := l_count + 1 a_file.put_string (s)
if end_of_input then if end_of_input or s.count < n then
-- Jump out of the loop. n := s.count
i := end_pos + 1 -- no more data
l_remaining := l_remaining - n
n := 0
else else
i := i + 1 n := s.count
l_remaining := l_remaining - n
end end
end end
last_appended_count := l_count last_appended_count := nb - l_remaining
-- Clean `last_string'
last_string.wipe_out
ensure ensure
nb_char_read_large_enough: last_appended_count >= 0 nb_char_read_large_enough: last_appended_count >= 0
nb_char_read_small_enough: last_appended_count <= nb nb_char_read_small_enough: last_appended_count <= nb
@@ -206,7 +214,7 @@ feature -- Status report
end end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software