pub fn IndexFunc(s: impl AsRef<[byte]>, f: fn(rune) -> bool) -> intExpand description
IndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the first Unicode code point satisfying f(c), or -1 if none do.
zh-cn
IndexFunc将满足f(rune)的第一个Unicode代码点的索引返回到s,如果没有,则返回-1。§Example
use gostd_bytes as bytes;
/* fn f(c: u32) -> bool {
let s = char::from_u32(c).unwrap();
!s.is_ascii()
} */
// 用上面注释掉的函数也可以,用下面的匿名函数也可以。
let f = |c: u32| {
let s = char::from_u32(c).expect("u32 to char failed!");
!s.is_ascii()
};
assert_eq!(7, bytes::IndexFunc("Hello, 世界", f));
assert_eq!(-1, bytes::IndexFunc("Hello, world", f));
assert_eq!(7, bytes::IndexFunc("Hello, 世界".as_bytes(), f));
assert_eq!(-1, bytes::IndexFunc("Hello, world".to_string(), f));