mirror of
https://github.com/helix-editor/helix.git
synced 2024-12-19 06:21:53 +04:00
27 lines
689 B
Rust
27 lines
689 B
Rust
|
use ropey::RopeSlice;
|
||
|
|
||
|
pub trait RopeSliceExt: Sized {
|
||
|
fn ends_with(self, text: &str) -> bool;
|
||
|
fn starts_with(self, text: &str) -> bool;
|
||
|
}
|
||
|
|
||
|
impl RopeSliceExt for RopeSlice<'_> {
|
||
|
fn ends_with(self, text: &str) -> bool {
|
||
|
let len = self.len_bytes();
|
||
|
if len < text.len() {
|
||
|
return false;
|
||
|
}
|
||
|
self.get_byte_slice(len - text.len()..)
|
||
|
.map_or(false, |end| end == text)
|
||
|
}
|
||
|
|
||
|
fn starts_with(self, text: &str) -> bool {
|
||
|
let len = self.len_bytes();
|
||
|
if len < text.len() {
|
||
|
return false;
|
||
|
}
|
||
|
self.get_byte_slice(..len - text.len())
|
||
|
.map_or(false, |start| start == text)
|
||
|
}
|
||
|
}
|