fn verify_section_sorted(toml_data: &[u8], header: &str) -> Result<(), String> {
    let mut in_section = false;
    let mut prev = None;
    for line in toml_data.split(|c| *c == b'\n') {
        let line: Vec<u8> = line
            .iter()
            .filter(|c| !c.is_ascii_whitespace())
            .copied()
            .collect();

        if line.is_empty() {
            continue;
        }

        if in_section {
            if line.starts_with(&[b'[']) {
                break;
            }

            if line.starts_with(&[b'#']) {
                continue;
            }

            let mut it = line.split(|c| *c == b'=');
            if let Some(dep_name) = it.next() {
                let dep_name = String::from_utf8_lossy(dep_name).into_owned();
                if let Some(p) = prev {
                    if p > dep_name {
                        return Err(format!(
                            "not sorted correctly: {} is specified after {}",
                            dep_name, p
                        ));
                    }
                }
                prev = Some(dep_name);
            }
        } else {
            in_section = line.starts_with(header.as_bytes());
        }
    }

    Ok(())
}
/// Verify that a section is sorted if it exists
Verify that a section is sorted if it exists
Verify that a section is sorted if it exists
fn verify_section_sorted(toml_data: &[u8], header: &str) -> Result<(), String> {
    let mut in_section = false;
    let mut prev = None;
    for line in toml_data.split(|c| *c == b'\n') {
        let line: Vec<u8> = line
            .iter()
            .filter(|c| !c.is_ascii_whitespace())
            .copied()
            .collect();
        if line.is_empty() {
            continue;
        }
        if in_section {
            if line.starts_with(&[b'[']) {
                break;
            }
            if line.starts_with(&[b'#']) {
                continue;
            }
            let mut it = line.split(|c| *c == b'=');
            if let Some(dep_name) = it.next() {
                let dep_name = String::from_utf8_lossy(dep_name).into_owned();
                if let Some(p) = prev {
                    if p > dep_name {
                        return Err(format!(
                            "not sorted correctly: {} is specified after {}",
                            dep_name, p
                        ));
                    }
                }
                prev = Some(dep_name);
            }
        } else {
            in_section = line.starts_with(header.as_bytes());
        }
    }
    Ok(())
}
fn verify_section_sorted ( toml_data : & [ u8 ] , header : & str ) -> Result < ( ) , String > { let mut in_section = false ; let mut prev = None ; for line in toml_data . split ( | c | * c == b'\n' ) { let line : Vec < u8 > = line . iter ( ) . filter ( | c | ! c . is_ascii_whitespace ( ) ) . copied ( ) . collect ( ) ; if line . is_empty ( ) { continue ; } if in_section { if line . starts_with ( & [ b'[' ] ) { break ; } if line . starts_with ( & [ b'#' ] ) { continue ; } let mut it = line . split ( | c | * c == b'=' ) ; if let Some ( dep_name ) = it . next ( ) { let dep_name = String :: from_utf8_lossy ( dep_name ) . into_owned ( ) ; if let Some ( p ) = prev { if p > dep_name { return Err ( format ! ( " " dep_name p ) ) ; } } prev = Some ( dep_name ) ; } } else { in_section = line . starts_with ( header . as_bytes ( ) ) ; } } Ok ( ( ) ) }
Verify that a section is sorted if it exists
Verify that a section is sorted if it exists
toml_data
&[u8]
header
&str
toml_data
&[u8]
header
&str