Debian Codegraph @

debian/rust-vendor/bstr/src/unicode/whitespace.rs

raw
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::new(slice).anchored(Anchored::Yes);
11 WHITESPACE_ANCHORED_FWD
12 .try_search_fwd(&input)
13 .unwrap()
14 .map_or(0, |hm| 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::new(slice).anchored(Anchored::Yes);
20 WHITESPACE_ANCHORED_REV
21 .try_search_rev(&input)
22 .unwrap()
23 .map_or(slice.len(), |hm| hm.offset())
24 }