Counts the number of UTF-8 characters in the text. This function efficiently counts UTF-8 characters by identifying character start bytes (non-continuation bytes). Uses SIMD acceleration when available. # Arguments `text`: The UTF-8 encoded byte slice to count characters in. # Returns The number of UTF-8 characters (codepoints) in the text. # Examples ``` use stringzilla::stringzilla as sz;
(text: T)
| 1875 | /// assert_eq!(sz::count_utf8(text_cjk), 4); |
| 1876 | /// ``` |
| 1877 | pub fn count_utf8<T>(text: T) -> usize |
| 1878 | where |
| 1879 | T: AsRef<[u8]>, |
| 1880 | { |
| 1881 | let text_ref = text.as_ref(); |
| 1882 | let text_pointer = text_ref.as_ptr() as *const c_void; |
| 1883 | let text_length = text_ref.len(); |
| 1884 | |
| 1885 | unsafe { sz_utf8_count(text_pointer, text_length) } |
| 1886 | } |
| 1887 | |
| 1888 | /// Finds the byte offset of the Nth UTF-8 character (0-indexed). |
| 1889 | /// |
no test coverage detected
searching dependent graphs…