| 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 | pub fn whitespace_len_fwd(slice: &[u8]) -> usize { | 
|---|
| 10 | let input: Input<'_> = Input::new(slice).anchored(mode:Anchored::Yes); | 
|---|
| 11 | WHITESPACE_ANCHORED_FWD | 
|---|
| 12 | .try_search_fwd(&input) | 
|---|
| 13 | .unwrap() | 
|---|
| 14 | .map_or(default:0, |hm: HalfMatch| hm.offset()) | 
|---|
| 15 | } | 
|---|
| 16 |  | 
|---|
| 17 | /// Return the last position of a non-whitespace character. | 
|---|
| 18 | pub fn whitespace_len_rev(slice: &[u8]) -> usize { | 
|---|
| 19 | let input: Input<'_> = Input::new(slice).anchored(mode:Anchored::Yes); | 
|---|
| 20 | WHITESPACE_ANCHORED_REV | 
|---|
| 21 | .try_search_rev(&input) | 
|---|
| 22 | .unwrap() | 
|---|
| 23 | .map_or(default:slice.len(), |hm: HalfMatch| hm.offset()) | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|