summaryrefslogtreecommitdiffstats
path: root/vendor/bstr/src/unicode/whitespace.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/bstr/src/unicode/whitespace.rs
parentInitial commit. (diff)
downloadcargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.tar.xz
cargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bstr/src/unicode/whitespace.rs')
-rw-r--r--vendor/bstr/src/unicode/whitespace.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/bstr/src/unicode/whitespace.rs b/vendor/bstr/src/unicode/whitespace.rs
new file mode 100644
index 0000000..bf1f47c
--- /dev/null
+++ b/vendor/bstr/src/unicode/whitespace.rs
@@ -0,0 +1,24 @@
+use regex_automata::{dfa::Automaton, Anchored, Input};
+
+use crate::unicode::fsm::{
+ whitespace_anchored_fwd::WHITESPACE_ANCHORED_FWD,
+ whitespace_anchored_rev::WHITESPACE_ANCHORED_REV,
+};
+
+/// Return the first position of a non-whitespace character.
+pub fn whitespace_len_fwd(slice: &[u8]) -> usize {
+ let input = Input::new(slice).anchored(Anchored::Yes);
+ WHITESPACE_ANCHORED_FWD
+ .try_search_fwd(&input)
+ .unwrap()
+ .map_or(0, |hm| hm.offset())
+}
+
+/// Return the last position of a non-whitespace character.
+pub fn whitespace_len_rev(slice: &[u8]) -> usize {
+ let input = Input::new(slice).anchored(Anchored::Yes);
+ WHITESPACE_ANCHORED_REV
+ .try_search_rev(&input)
+ .unwrap()
+ .map_or(slice.len(), |hm| hm.offset())
+}