~maxgyver83/emailbook-hare

33dc0ab65b45e7f8ae6f22f4c3b6f1eb6e71d09f — Max Schillinger 8 months ago 3276481 use-u8-slices-for-joining-lines
Use u8 slices for joining lines
1 files changed, 9 insertions(+), 8 deletions(-)

M emailbook-hare.ha
M emailbook-hare.ha => emailbook-hare.ha +9 -8
@@ 214,7 214,7 @@ fn parse_file(filename: str, lines: *[]str) void = {
	const file = os::open(filename)!;
	defer io::close(file)!;
	let continuation = false;
	const joined_lines: str = "";
	const joined_lines: []u8 = [];

	for (true) {
		const line = match (bufio::read_line(file)) {


@@ 230,21 230,22 @@ fn parse_file(filename: str, lines: *[]str) void = {
		};
		const index = starts_with_any(line, fields);
		if (index >= 0) {
			if (joined_lines != "") {
				process_line(joined_lines);
				joined_lines = "";
			if (len(joined_lines) > 0) {
				process_line(strings::fromutf8_unsafe(joined_lines));
				joined_lines = [];
			};
			continuation = true;
			joined_lines = strings::trim(strings::sub(line, len(fields[index]), strings::end));
			// can slices be trimmed?
			joined_lines = strings::toutf8(line)[len(fields[index])..];
		} else if (continuation && strings::hasprefix(line, " ")) {
			joined_lines = strings::concat(joined_lines, line);
			append(joined_lines, strings::toutf8(line));
		} else {
			continuation = false;
		};

	};
	if (joined_lines != "") {
		process_line(joined_lines);
	if (len(joined_lines) > 0) {
		process_line(strings::fromutf8_unsafe(joined_lines));
	};
};