1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
pub mod file;
#[cfg(feature = "vecbuffer")]
mod vecbuffer;
#[cfg(feature = "vecbuffer")]
pub use vecbuffer::*;
pub trait Buffer {
fn len(&self)
-> usize ;
fn get_tag(&self, tag: char)
-> Result<usize, &'static str> ;
fn get_matching(&self, pattern: &str, curr_line: usize, backwards: bool)
-> Result<usize, &'static str> ;
fn mark_matching(&mut self, pattern: &str, selection: (usize, usize), inverse: bool)
-> Result<(), &'static str> ;
fn get_marked(&mut self)
-> Result<Option<usize>, &'static str> ;
fn tag_line(&mut self, index: usize, tag: char)
-> Result<(), &'static str> ;
fn insert<'a>(&mut self, data: &mut dyn Iterator<Item = &'a str>, index: usize)
-> Result<(), &'static str> ;
fn cut(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn change<'a>(&mut self, data: &mut dyn Iterator<Item = &'a str>, selection: (usize, usize))
-> Result<(), &'static str> ;
fn mov(&mut self, selection: (usize, usize), index: usize)
-> Result<(), &'static str> ;
fn mov_copy(&mut self, selection: (usize, usize), index: usize)
-> Result<(), &'static str> ;
fn join(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn copy(&mut self, selection: (usize, usize))
-> Result<(), &'static str> ;
fn paste(&mut self, index: usize)
-> Result<usize, &'static str> ;
fn search_replace(&mut self, pattern: (&str, &str), selection: (usize, usize), global: bool)
-> Result<(usize, usize), &'static str> ;
fn read_from(&mut self, path: &str, index: Option<usize>, must_exist: bool)
-> Result<usize, &'static str> ;
fn write_to(&mut self, selection: Option<(usize, usize)>, path: &str, append: bool)
-> Result<(), &'static str> ;
fn saved(&self)
-> bool ;
fn get_selection<'a>(&'a self, selection: (usize, usize))
-> Result<Box<dyn Iterator<Item = &'a str> + 'a>, &'static str> ;
}
pub fn verify_index(
buffer: &impl Buffer,
index: usize,
) -> Result<(), &'static str> {
if index > buffer.len() { return Err(crate::error_consts::INDEX_TOO_BIG); }
Ok(())
}
pub fn verify_selection(
buffer: &impl Buffer,
selection: (usize, usize),
) -> Result<(), &'static str> {
if selection.0 > selection.1 { return Err(crate::error_consts::SELECTION_EMPTY); }
if selection.1 >= buffer.len() { return Err(crate::error_consts::INDEX_TOO_BIG); }
Ok(())
}