#[cfg(feature = "index")]
use std::ops::Range;
use crate::PslError;
use crate::model::block::Blocks;
use super::common::{PslMeta, looks_like_record, parse_record, read_line};
pub(crate) fn parse_psl_sequential(buf: &[u8]) -> Result<(Vec<PslMeta>, Blocks), PslError> {
let mut metas = Vec::new();
let mut blocks = Blocks::new();
let mut pos = 0usize;
let len = buf.len();
while pos < len {
let line_start = pos;
let (next_pos, line) = read_line(buf, pos);
pos = next_pos;
if !looks_like_record(line) {
continue;
}
let meta = parse_record(line, line_start, &mut blocks)?;
metas.push(meta);
}
Ok((metas, blocks))
}
#[cfg(feature = "index")]
pub(crate) fn locate_line_ranges(buf: &[u8]) -> Vec<Range<usize>> {
let mut ranges = Vec::new();
let mut pos = 0usize;
let len = buf.len();
while pos < len {
let line_start = pos;
let (next_pos, line) = read_line(buf, pos);
pos = next_pos;
if !looks_like_record(line) {
continue;
}
ranges.push(line_start..(line_start + line.len()));
}
ranges
}