/// Returns the lines in `buf` that are terminated by newline.
/// Also returned is the number of bytes consumed by the discovered lines.
pub fn parse_lines(buf: &[u8]) -> (Vec<&[u8]>, usize) {
    let mut ret = Vec::new();
    let mut x = 0;
    let mut skip = false;
    for (i, b) in buf.iter().enumerate() {
        if skip {
            skip = false;
            continue;
        }
        if *b == 0xa {
            let s = &buf[x..i];
            ret.push(s);
            x = 1 + i;
            skip = true;
        }
    }
    (ret, x)
}

#[test]
fn test_parse_00() {
    let ret = parse_lines(b"line00\nline01\nline02\n");
    assert_eq!(ret.0, vec![b"line00", b"line01", b"line02"]);
}

#[test]
fn test_parse_01() {
    let ret = parse_lines(b"");
    assert_eq!(ret.0.len(), 0);
}

#[test]
fn test_parse_02() {
    let ret = parse_lines(b"line00");
    assert_eq!(ret.0.len(), 0);
}

#[test]
fn test_parse_03() {
    let ret = parse_lines(b"line00\nline01\nline02");
    assert_eq!(ret.0, vec![b"line00", b"line01"]);
}
