djr 0.0.1

Djot parser written in pure Rust
Documentation
use super::unicode::{is_blank, is_line_ending};

pub(crate) fn read_until(byte: u8, bytes: &[u8]) -> usize {
    let mut escaped = false;
    bytes.iter().take_while(|&&c| {
        if escaped {
            escaped = false;
            return true
        }

        if c == b'\\' {
            escaped = true;
        }

        c != byte
    }).count()
}

pub(crate) fn read_line(bytes: &[u8]) -> usize {
    bytes.iter().take_while(|c| !is_line_ending(**c)).count()
}

pub(crate) fn read_while<P>(bytes: &[u8], mut pred: P) -> usize
where
    P: FnMut(u8) -> bool,
{
    bytes.iter().take_while(|&&c| pred(c)).count()
}

/// Counts the number of bytes that contribute to the indentation of a line.
///
/// This is in contrast to [`get_indentation`], which gets the indentation level, and thus
/// considers tabs to be a length of four. This function just counts the bytes.
pub(crate) fn read_indentation(bytes: &[u8]) -> usize {
    bytes.iter().take_while(|&&c| is_blank(c)).count()
}