INNER CODE UNIT · Rust

parse_enclosed

steineggerlab/folddisco · lib/pdbtbx-cif/src/lib.rs:396

fn parse_enclosed<'a>(input: &mut Position<'a>, pat: char) -> Result<&'a str, PDBError> {
    let mut chars_to_remove = 1; //Assume the first position is 'pat'

    for c in input.text.chars().skip(1) {
        if c == pat {
            let trimmed = &input.text[1..chars_to_remove];
            input.text = &input.text[(chars_to_remove + 1)..];
            input.column += chars_to_remove + 1;
            return Ok(trimmed);
        } else if c == '\n' || c == '\r' {
            let mut end = *input;
            end.text = &input.text[(chars_to_remove + 1)..];
            end.column += chars_to_remove + 1;
            return Err(PDBError::new(
                ErrorLevel::BreakingError,
                "Invalid enclosing",
                format!("This element was enclosed by \'{pat}\' but the closing delimiter was not found."),
                Context::range(input, &end),

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…