add tests for io::readchars and io::readchar

Additionally reformat so that 'make check' passes.
This commit is contained in:
Grahame Bowland
2012-01-09 20:49:17 +08:00
parent bcc25634e6
commit ba694775f5
2 changed files with 58 additions and 7 deletions

View File

@@ -130,26 +130,29 @@ obj new_reader(rdr: buf_reader) {
val += next & 63 as uint;
}
// See str::char_at
val += (b0 << (w + 1u as u8) as uint) << (w - 1u) * 6u - w - 1u;
val += (b0 << (w + 1u as u8) as uint)
<< (w - 1u) * 6u - w - 1u;
chars += [ val as char ];
}
ret (i, 0u);
}
let buf: [u8] = [];
let chars: [char] = [];
let nbread = n; // might need more bytes, but reading n will never over-read
// might need more bytes, but reading n will never over-read
let nbread = n;
while nbread > 0u {
let data = self.read_bytes(nbread);
let data = self.read_bytes(nbread);
if vec::len(data) == 0u {
// eof - FIXME should we do something if we're split in a unicode char?
// eof - FIXME should we do something if
// we're split in a unicode char?
break;
}
buf += data;
let (offset, nbreq) = chars_from_buf(buf, chars);
let ncreq = n - vec::len(chars);
// again we either know we need a certain number of bytes to complete a
// character, or we make sure we don't over-read by reading 1-byte per char
// needed
// again we either know we need a certain number of bytes
// to complete a character, or we make sure we don't
// over-read by reading 1-byte per char needed
nbread = if ncreq > nbreq { ncreq } else { nbreq };
if nbread > 0u {
buf = vec::slice(buf, offset, vec::len(buf));