MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / find_whitespace_utf8

Function find_whitespace_utf8

rust/stringzilla.rs:1829–1848  ·  view source on GitHub ↗

Finds the first whitespace character in UTF-8 encoded text. Searches for any of the 29 Unicode whitespace characters (includes all newlines per Unicode standard, plus spaces, tabs, and various Unicode space characters). The complete set includes: - All 8 newline characters (see [`find_newline_utf8`]) - U+0009 (CHARACTER TABULATION `\t`) - U+001F (UNIT SEPARATOR) - U+0020 (SPACE) - U+00A0 (NO-BRE

(text: T)

Source from the content-addressed store, hash-verified

1827/// assert_eq!(span.length, 1);
1828/// ```
1829pub fn find_whitespace_utf8<T>(text: T) -> Option<IndexSpan>
1830where
1831 T: AsRef<[u8]>,
1832{
1833 let text_ref = text.as_ref();
1834 let text_pointer = text_ref.as_ptr() as *const c_void;
1835 let text_length = text_ref.len();
1836 let mut matched_length: usize = 0;
1837
1838 let result = unsafe { sz_utf8_find_whitespace(text_pointer, text_length, &mut matched_length as *mut usize) };
1839
1840 if result.is_null() {
1841 None
1842 } else {
1843 let offset = unsafe { (result as *const u8).offset_from(text_pointer as *const u8) }
1844 .try_into()
1845 .unwrap();
1846 Some(IndexSpan::new(offset, matched_length))
1847 }
1848}
1849
1850/// Counts the number of UTF-8 characters in the text.
1851///

Callers 11

nextMethod · 0.85
find_whitespace_utf8_tabFunction · 0.85
find_whitespace_utf8_crFunction · 0.85
find_whitespace_utf8Method · 0.85

Calls 3

as_ptrMethod · 0.80
lenMethod · 0.80
sz_utf8_find_whitespaceFunction · 0.50

Used in the wild real call sites across dependent graphs

searching dependent graphs…