summaryrefslogtreecommitdiffstats
path: root/third_party/rust/fluent-syntax/src/parser/slice.rs
blob: d44f8251fe29e599c40ff5905f16f6ba3b88ecfa (plain)
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
use std::ops::Range;
pub trait Slice<'s>: AsRef<str> + Clone + PartialEq {
    fn slice(&self, range: Range<usize>) -> Self;
    fn trim(&mut self);
}

impl<'s> Slice<'s> for String {
    fn slice(&self, range: Range<usize>) -> Self {
        self[range].to_string()
    }

    fn trim(&mut self) {
        *self = self.trim_end().to_string();
    }
}

impl<'s> Slice<'s> for &'s str {
    fn slice(&self, range: Range<usize>) -> Self {
        &self[range]
    }

    fn trim(&mut self) {
        *self = self.trim_end();
    }
}