use crate::grapheme::Grapheme;
use crate::{Cursor, TextError, TextPosition, TextRange, upos_type};
use std::borrow::Cow;
use std::ops::Range;
pub(crate) mod text_rope;
pub(crate) mod text_string;
pub trait SkipLine: Iterator {
fn skip_line(&mut self) -> Result<(), TextError>;
fn skip_to(&mut self, byte_pos: usize) -> Result<(), TextError>;
}
pub trait TextStore {
type GraphemeIter<'a>: Cursor<Item = Grapheme<'a>> + SkipLine + Clone
where
Self: 'a;
fn is_multi_line(&self) -> bool;
fn has_final_newline(&self) -> bool;
fn len_lines(&self) -> upos_type;
fn len_bytes(&self) -> usize;
fn cache_validity(&self) -> Option<usize>;
fn string(&self) -> String;
fn set_string(&mut self, t: &str);
fn byte_range_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>;
fn byte_range(&self, range: TextRange) -> Result<Range<usize>, TextError>;
fn byte_to_pos(&self, byte: usize) -> Result<TextPosition, TextError>;
fn bytes_to_range(&self, bytes: Range<usize>) -> Result<TextRange, TextError>;
fn str_slice(&self, range: TextRange) -> Result<Cow<'_, str>, TextError>;
fn str_slice_byte(&self, range: Range<usize>) -> Result<Cow<'_, str>, TextError>;
fn graphemes_byte(
&self,
range: Range<usize>,
pos: usize,
) -> Result<Self::GraphemeIter<'_>, TextError>;
fn line_at(&self, row: upos_type) -> Result<Cow<'_, str>, TextError>;
fn lines_at(&self, row: upos_type) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>;
fn line_graphemes(&self, row: upos_type) -> Result<Self::GraphemeIter<'_>, TextError>;
fn line_width(&self, row: upos_type) -> Result<upos_type, TextError>;
fn insert_char(
&mut self,
pos: TextPosition,
c: char,
) -> Result<(TextRange, Range<usize>), TextError>;
fn insert_str(
&mut self,
pos: TextPosition,
t: &str,
) -> Result<(TextRange, Range<usize>), TextError>;
fn remove(
&mut self,
range: TextRange,
) -> Result<(String, (TextRange, Range<usize>)), TextError>;
fn insert_b(&mut self, byte_pos: usize, t: &str) -> Result<(), TextError>;
fn remove_b(&mut self, byte_range: Range<usize>) -> Result<(), TextError>;
}