# 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.
+ # Is automatically invoked at the end of `with` structures.
#
# call `close` by default.
fun finish do close
fun read_bytes(i: Int): Bytes
do
if last_error != null then return new Bytes.empty
- var s = new NativeString(i)
+ var s = new CString(i)
var buf = new Bytes(s, 0, 0)
while i > 0 and not eof do
var c = read_byte
while c < full_len do c = c * 2 + 2
_buffer_capacity = c
end
- var nns = new NativeString(_buffer_capacity)
+ var nns = new CString(_buffer_capacity)
bf.items.copy_to(nns, bf.length, 0, 0)
_buffer.copy_to(nns, remsp, _buffer_pos, bf.length)
_buffer = nns
end
# The buffer
- private var buffer: NativeString = new NativeString(0)
+ private var buffer: CString = new CString(0)
# The current position in the buffer
private var buffer_pos = 0
# Allocate a `_buffer` for a given `capacity`.
protected fun prepare_buffer(capacity: Int)
do
- _buffer = new NativeString(capacity)
+ _buffer = new CString(capacity)
_buffer_pos = 0 # need to read
_buffer_length = 0
_buffer_capacity = capacity
class StringWriter
super Writer
- private var content = new Array[String]
- redef fun to_s do return content.plain_to_s
+ private var content = new Buffer
+ redef fun to_s do return content.to_s
redef fun is_writable do return not closed
redef fun write_bytes(b) do
- content.add(b.to_s)
+ content.append(b.to_s)
end
redef fun write(str)
do
assert not closed
- content.add(str.to_s)
+ content.append(str)
+ end
+
+ redef fun write_char(c)
+ do
+ assert not closed
+ content.add(c)
end
# Is the stream closed?
redef fun read_all_bytes do
var nslen = source.length - cursor
- var nns = new NativeString(nslen)
+ var nns = new CString(nslen)
source.copy_to_native(nns, nslen, cursor, 0)
return new Bytes(nns, nslen, nslen)
end