X-Git-Url: http://nitlanguage.org diff --git a/lib/core/stream.nit b/lib/core/stream.nit index 4b1e826..e8cb232 100644 --- a/lib/core/stream.nit +++ b/lib/core/stream.nit @@ -39,6 +39,26 @@ abstract class Stream # close the stream fun close is abstract + + # Pre-work hook. + # + # Used to inform `self` that operations will start. + # Specific streams can use this to prepare some resources. + # + # Is automatically invoked at the beginning of `with` structures. + # + # Do nothing by default. + fun start do end + + # Post-work hook. + # + # Used to inform `self` that the operations are over. + # Specific streams can use this to free some resources. + # + # Is automatically invoked at the end of `woth` structures. + # + # call `close` by default. + fun finish do close end # A `Stream` that can be read from @@ -275,7 +295,7 @@ abstract class Reader # ~~~ # var w = new StringReader(" Hello, \n\t World!") # assert w.read_word == "Hello," - # assert w.read_char == '\n'.ascii + # assert w.read_char == '\n' # assert w.read_word == "World!" # assert w.read_word == "" # ~~~ @@ -425,6 +445,13 @@ interface Writable end end +redef class Bytes + super Writable + redef fun write_to(s) do s.write_bytes(self) + + redef fun write_to_string do return to_s +end + redef class Text super Writable redef fun write_to(stream) do stream.write(self) @@ -441,7 +468,7 @@ abstract class BufferedReader return null end # TODO: Fix when supporting UTF-8 - var c = _buffer[_buffer_pos].to_i.ascii + var c = _buffer[_buffer_pos].to_i.code_point _buffer_pos += 1 return c end