use crate::offsets::{java_strip, java_strip_leading, utf16_index, utf16_len};
use crate::span::Span;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RowCells {
pub cells: Vec<String>,
pub cell_spans: Vec<Span>,
}
pub fn parse_row_cells(line_text: &str, line_start_offset: usize, source: &str) -> RowCells {
let (Some(first), Some(last)) = (line_text.find('|'), line_text.rfind('|')) else {
return RowCells {
cells: Vec::new(),
cell_spans: Vec::new(),
};
};
if last <= first {
return RowCells {
cells: Vec::new(),
cell_spans: Vec::new(),
};
}
let inner = &line_text[first + 1..last];
let inner_start = utf16_index(line_text, first + 1);
let mut cells = Vec::new();
let mut cell_spans = Vec::new();
let mut cursor = 0usize;
for seg in inner.split('|') {
let trimmed = java_strip(seg);
let leading = utf16_len(seg) - utf16_len(java_strip_leading(seg));
let abs_start = line_start_offset + inner_start + cursor + leading;
cell_spans.push(Span::from_offsets(source, abs_start, abs_start + utf16_len(trimmed)));
cells.push(trimmed.to_string());
cursor += utf16_len(seg) + 1; }
RowCells { cells, cell_spans }
}