# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
-# This module handle abstract input and output streams
-package stream
+# Input and output streams of characters
+module stream
import string
return s.to_s
end
- # Read a string until the end of the line and append it to `s'.
+ # Read a string until the end of the line and append it to `s`.
fun append_line_to(s: Buffer)
do
loop
# Is the last fill_buffer reach the end
protected fun end_reached: Bool is abstract
- # Allocate a `_buffer' for a given `capacity'.
+ # Allocate a `_buffer` for a given `capacity`.
protected fun prepare_buffer(capacity: Int)
do
_buffer = new Buffer.with_capacity(capacity)
private fun native_read_char(i: Int): Int is extern "stream_FDStream_FDStream_native_read_char_1"
private fun native_read(i: Int, buf: NativeString, len: Int): Int is extern "stream_FDStream_FDStream_native_read_3"
private fun native_write(i: Int, buf: NativeString, len: Int): Int is extern "stream_FDStream_FDStream_native_write_3"
+ private fun native_write_char(i: Int, c: Char): Int is extern "stream_FDStream_FDStream_native_write_char_2"
init(fd: Int) do self.fd = fd
end
private fun intern_poll( in_fds : Array[Int], out_fds : Array[Int] ) : nullable Int is extern import Array::length, Array::[], nullable Object as ( Int ), Int as nullable
end
+
+# Stream to a String. Mainly used for compatibility with OStream type and tests.
+class StringOStream
+ super OStream
+
+ private var content = new Array[String]
+ redef fun to_s do return content.to_s
+ redef fun is_writable do return true
+ redef fun write(str) do content.add(str)
+end