| 1 |
use std::ops::Range; |
| 2 |
|
| 3 |
pub(crate) fn matches_fluent_ws(c: char) -> bool { |
| 4 |
c == ' ' || c == '\r' || c == '\n' |
| 5 |
} |
| 6 |
|
| 7 |
pub trait Slice<'s>: AsRef<str> + Clone + PartialEq { |
| 8 |
fn slice(&self, range: Range<usize>) -> Self; |
| 9 |
fn trim(&mut self); |
| 10 |
} |
| 11 |
|
| 12 |
impl Slice<'_> for String { |
| 13 |
fn slice(&self, range: Range<usize>) -> Self { |
| 14 |
self[range].to_string() |
| 15 |
} |
| 16 |
|
| 17 |
fn trim(&mut self) { |
| 18 |
*self = self.trim_end_matches(matches_fluent_ws).to_string(); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl<'s> Slice<'s> for &'s str { |
| 23 |
fn slice(&self, range: Range<usize>) -> Self { |
| 24 |
&self[range] |
| 25 |
} |
| 26 |
|
| 27 |
fn trim(&mut self) { |
| 28 |
*self = self.trim_end_matches(matches_fluent_ws); |
| 29 |
} |
| 30 |
} |