fn markup_text_next_tok()

in resctl-demo/src/doc/markup_rd.rs [127:163]


fn markup_text_next_tok(chars: &mut std::iter::Peekable<std::str::Chars>) -> (String, bool) {
    let mut tok = String::new();

    match chars.peek() {
        Some(&first) if first == '*' || first == '_' => loop {
            tok.push(chars.next().unwrap());
            match chars.peek() {
                Some(&c) if c == first => continue,
                _ => break,
            }
        },
        Some(&first) if first == '%' => loop {
            tok.push(chars.next().unwrap());
            match chars.peek() {
                Some(&c) if c == '%' => {
                    tok.push(chars.next().unwrap());
                    break;
                }
                Some(&c) if c != '*' && c != '_' && !c.is_whitespace() => continue,
                _ => break,
            }
        },
        Some(_) => loop {
            tok.push(chars.next().unwrap());
            match chars.peek() {
                Some(&c) if c != '*' && c != '_' && c != '%' => continue,
                _ => break,
            }
        },
        None => {}
    }
    let next_is_space = match chars.peek() {
        Some(&c) if c.is_whitespace() => true,
        _ => false,
    };
    (tok, next_is_space)
}