Function git_attributes::parse

source ·
pub fn parse(bytes: &[u8]) -> Lines<'_> 
Expand description

Parse attribute assignments line by line from bytes.

Examples found in repository?
src/match_group.rs (line 68)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    fn bytes_to_patterns(bytes: &[u8]) -> Vec<PatternMapping<Self::Value>> {
        crate::parse(bytes)
            .filter_map(Result::ok)
            .filter_map(|(pattern_kind, assignments, line_number)| {
                let (pattern, value) = match pattern_kind {
                    crate::parse::Kind::Macro(macro_name) => (
                        git_glob::Pattern {
                            text: macro_name.as_str().into(),
                            mode: git_glob::pattern::Mode::all(),
                            first_wildcard_pos: None,
                        },
                        Value::MacroAttributes(into_owned_assignments(assignments).ok()?),
                    ),
                    crate::parse::Kind::Pattern(p) => (
                        (!p.is_negative()).then(|| p)?,
                        Value::Assignments(into_owned_assignments(assignments).ok()?),
                    ),
                };
                PatternMapping {
                    pattern,
                    value,
                    sequence_number: line_number,
                }
                .into()
            })
            .collect()
    }