pub(crate) fn field(line: &str, start: usize, end: usize) -> Option<&str> {
let s = line.get(start..end.min(line.len()))?.trim();
if s.is_empty() {
None
} else {
Some(s)
}
}
pub(crate) fn raw_field(line: &str, start: usize, end: usize) -> &str {
let s = floor_char_boundary(line, start);
let e = floor_char_boundary(line, end);
if e <= s {
return "";
}
&line[s..e]
}
pub(crate) fn raw_field_from(line: &str, start: usize) -> &str {
let s = floor_char_boundary(line, start);
&line[s..]
}
pub(crate) fn fortran_f64(line: &str, start: usize, end: usize) -> Option<f64> {
let s = field(line, start, end)?;
s.replace(['D', 'd'], "e").parse::<f64>().ok()
}
fn floor_char_boundary(line: &str, index: usize) -> usize {
let mut i = index.min(line.len());
while i > 0 && !line.is_char_boundary(i) {
i -= 1;
}
i
}