@@ 1,7 1,7 @@
use ascii;
use io;
use strings;
-use strio;
+use memio;
const valid_field: str = "!#$%&'*+-.^_`|~";
@@ 39,7 39,7 @@ fn valid_header_value(b: u8) bool = {
// is returned.
export fn canonical_mime_header_key(key: str) str = {
let upper = true;
- let sink = strio::dynamic();
+ let sink = memio::dynamic();
const iter = strings::iter(key);
for (true) {
@@ 55,15 55,15 @@ export fn canonical_mime_header_key(key: str) str = {
};
if (upper) {
- strio::appendrune(&sink, ascii::toupper(rn))!;
+ memio::appendrune(&sink, ascii::toupper(rn))!;
} else {
- strio::appendrune(&sink, ascii::tolower(rn))!;
+ memio::appendrune(&sink, ascii::tolower(rn))!;
};
upper = rn == '-';
};
- return strio::string(&sink);
+ return memio::string(&sink)!;
};
@test fn canonical_mime_header_key() void = {
@@ 5,9 5,9 @@ use errors;
use fmt;
use hash::fnv;
use io;
use memio;
use os;
use strings;
use strio;
use types;
export type header = struct {
@@ 310,8 310,8 @@ export fn header_set(head: *header, key: str, val: str) void = {
export fn read_header(
in: io::handle,
) (header | io::error | errors::invalid) = {
let buf: [os::BUFSIZ]u8 = [0...];
let rd = bufio::buffered(in, buf, []);
let buf: [os::BUFSZ]u8 = [0...];
let rd = bufio::init(in, buf, []);
// TODO: leaks on error
let head = new_header();
@@ 379,7 379,7 @@ export fn read_header(
" d=example.org; h=Subject:To:From; s=default; t=1577562184; v=1; b=;\r\n"
"\r\n";
const in = bufio::fixed(strings::toutf8(input), io::mode::READ);
const in = memio::fixed(strings::toutf8(input));
const head = read_header(&in)!;
defer header_finish(&head);
@@ 413,10 413,10 @@ export fn write_header(sink: io::handle, head: *header) (size | io::error) = {
header_add(&head, "FROM", "Harriet <harriet@harelang.org>");
header_add(&head, "to", "Drew DeVault <sir@cmpwn.com>");
const sink = strio::dynamic();
const sink = memio::dynamic();
defer io::close(&sink)!;
write_header(&sink, &head)!;
const result = strio::string(&sink);
const result = memio::string(&sink)!;
const expect =
"To: Drew DeVault <sir@cmpwn.com>\r\n"
@@ 443,16 443,16 @@ export fn write_header(sink: io::handle, head: *header) (size | io::error) = {
" d=example.org; h=Subject:To:From; s=default; t=1577562184; v=1; b=;\r\n"
"\r\n";
const in = bufio::fixed(strings::toutf8(input), io::mode::READ);
const in = memio::fixed(strings::toutf8(input));
const head = read_header(&in)!;
defer header_finish(&head);
const sink = strio::dynamic();
const sink = memio::dynamic();
defer io::close(&sink)!;
write_header(&sink, &head)!;
assert(strio::string(&sink) == input);
assert(memio::string(&sink)! == input);
};
// Initializes a new header field, duplicating the provided parameters.
@@ 496,9 496,9 @@ fn header_field_raw(hf: *header_field) ([]u8 | errors::invalid) = {
return errors::invalid;
};
let sink = bufio::dynamic(io::mode::WRITE);
let sink = memio::dynamic();
header_field_fmt(&sink, hf)!;
hf.raw = bufio::buffer(&sink);
hf.raw = memio::buffer(&sink);
return hf.raw;
};
@@ 602,7 602,7 @@ fn fold_line(v: []u8, max: size) ([]u8, []u8, bool) = {
// Decodes a header value, collapsing continuation lines as necessary. The
// caller must free the return value.
fn decode_header_value(v: []u8) str = {
const sink = strio::dynamic();
const sink = memio::dynamic();
for (true) {
const i = match (bytes::index(v, '\n')) {
case void =>
@@ 614,10 614,10 @@ fn decode_header_value(v: []u8) str = {
write_continued(&sink, v[..i]);
v = v[i+1..];
};
return strio::string(&sink);
return memio::string(&sink)!;
};
fn write_continued(sink: *strio::stream, v: []u8) void = {
fn write_continued(sink: *memio::stream, v: []u8) void = {
if (len(v) > 0 && v[len(v)-1] == '\r') {
v = v[..len(v)-1];
};
@@ 625,8 625,8 @@ fn write_continued(sink: *strio::stream, v: []u8) void = {
if (len(v) == 0) {
return;
};
if (len(strio::string(sink)) != 0) {
strio::appendrune(sink, ' ')!;
if (len(memio::buffer(sink)) != 0) {
memio::appendrune(sink, ' ')!;
};
io::write(sink, v)!;
};
@@ 634,7 634,7 @@ fn write_continued(sink: *strio::stream, v: []u8) void = {
// Reads a (possibly continued) line from a buffered stream. The caller must
// free the return value.
fn read_continued(
rd: *bufio::bufstream,
rd: *bufio::stream,
) ([]u8 | errors::invalid | io::error) = {
let line = match (bufio::scanline(rd)?) {
case let line: []u8 =>
@@ 665,7 665,7 @@ fn read_continued(
};
fn has_continuation(
rd: *bufio::bufstream,
rd: *bufio::stream,
) (bool | io::error) = {
const b = match (bufio::scanbyte(rd)?) {
case let b: u8 =>