# 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
# ~~~
fun read_all: String do
var s = read_all_bytes
- if not s.is_utf8 then s = s.clean_utf8
var slen = s.length
if slen == 0 then return ""
var rets = ""
var pos = 0
- var sits = s.items
+ var str = s.items.clean_utf8(slen)
+ slen = str.bytelen
+ var sits = str.items
var remsp = slen
while pos < slen do
# The 129 size was decided more or less arbitrarily
# ~~~
# 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 == ""
# ~~~
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