Line | Count | Source |
1 | use regex_automata::{dfa::Automaton, Anchored, Input}; | |
2 | ||
3 | use crate::unicode::fsm::{ | |
4 | whitespace_anchored_fwd::WHITESPACE_ANCHORED_FWD, | |
5 | whitespace_anchored_rev::WHITESPACE_ANCHORED_REV, | |
6 | }; | |
7 | ||
8 | /// Return the first position of a non-whitespace character. | |
9 | 0 | pub fn whitespace_len_fwd(slice: &[u8]) -> usize { |
10 | 0 | let input = Input::new(slice).anchored(Anchored::Yes); |
11 | 0 | WHITESPACE_ANCHORED_FWD |
12 | 0 | .try_search_fwd(&input) |
13 | 0 | .unwrap() |
14 | 0 | .map_or(0, |hm| hm.offset()) |
15 | 0 | } |
16 | ||
17 | /// Return the last position of a non-whitespace character. | |
18 | 0 | pub fn whitespace_len_rev(slice: &[u8]) -> usize { |
19 | 0 | let input = Input::new(slice).anchored(Anchored::Yes); |
20 | 0 | WHITESPACE_ANCHORED_REV |
21 | 0 | .try_search_rev(&input) |
22 | 0 | .unwrap() |
23 | 0 | .map_or(slice.len(), |hm| hm.offset()) |
24 | 0 | } |