diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-17 23:54:00 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-18 01:06:20 +0100 |
| commit | acae6e2a54f11b27bae343a15d9eff952323fe28 (patch) | |
| tree | 60b7f021a66436f9035441f40be965ffb9df3897 /src/parse | |
| parent | 980f898d553bec35bd94171d47fd86cb13e39b23 (diff) | |
List label styling
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/scanner.rs | 6 | ||||
| -rw-r--r-- | src/parse/tokens.rs | 2 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/parse/scanner.rs b/src/parse/scanner.rs index 81fa4fba..685503c3 100644 --- a/src/parse/scanner.rs +++ b/src/parse/scanner.rs @@ -90,6 +90,12 @@ impl<'s> Scanner<'s> { self.rest().chars().next() } + /// Get the nth-previous eaten char. + #[inline] + pub fn prev(&self, n: usize) -> Option<char> { + self.eaten().chars().nth_back(n) + } + /// Checks whether the next char fulfills a condition. /// /// Returns `default` if there is no next char. diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index ca2cb74a..e88b49f9 100644 --- a/src/parse/tokens.rs +++ b/src/parse/tokens.rs @@ -538,7 +538,7 @@ impl<'s> Tokens<'s> { fn in_word(&self) -> bool { let alphanumeric = |c: Option<char>| c.map_or(false, |c| c.is_alphanumeric()); - let prev = self.s.get(.. self.s.last_index()).chars().next_back(); + let prev = self.s.prev(1); let next = self.s.peek(); alphanumeric(prev) && alphanumeric(next) } |
