arch-pkg-text 0.10.0

Pure Rust library to parse Arch Linux packages' structured text formats
Documentation
use crate::srcinfo::field::RawField;
use pipe_trait::Pipe;

/// Parse a non-blank trimmed line.
pub fn parse_line(line: &str) -> Option<(RawField<'_>, &'_ str)> {
    let (field, value) = line.split_once('=')?;
    let field = field.trim_end().pipe(RawField::parse_raw);
    let value = value.trim_start();
    Some((field, value))
}

/// This function is intended for use in `.filter` to filter out lines to parse.
pub fn trimmed_line_is_blank(trimmed_line: &str) -> bool {
    trimmed_line.is_empty() || trimmed_line.starts_with('#')
}

/// List all trimmed lines that aren't blank.
pub fn non_blank_trimmed_lines(text: &str) -> impl Iterator<Item = &'_ str> {
    text.lines()
        .map(str::trim)
        .filter(|line| !trimmed_line_is_blank(line))
}