X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/stream.nit b/lib/standard/stream.nit index dce2a89..f161ebb 100644 --- a/lib/standard/stream.nit +++ b/lib/standard/stream.nit @@ -10,8 +10,8 @@ # 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 @@ -61,7 +61,7 @@ interface IStream 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 @@ -195,7 +195,7 @@ abstract class BufferedIStream # 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) @@ -221,6 +221,7 @@ abstract class FDStream 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 @@ -295,3 +296,13 @@ redef interface Object 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