Function LastIndexFunc

Source
pub fn LastIndexFunc(s: impl AsRef<[byte]>, f: fn(rune) -> bool) -> int
Expand description

LastIndexFunc interprets s as a sequence of UTF-8-encoded code points. It returns the byte index in s of the last Unicode code point satisfying f(c), or -1 if none do.

zh-cn s字节切片中最后一个满足函数f的unicode码值的位置,不存在则返回-1。

§Example

use gostd_bytes as bytes;

   let f = |x: u32| char::from_u32(x).unwrap().is_ascii_digit();

   assert_eq!(5, bytes::LastIndexFunc("go 123", f));
   assert_eq!(2, bytes::LastIndexFunc("123 go", f));
   assert_eq!(-1, bytes::LastIndexFunc("go", f));
   assert_eq!(5, bytes::LastIndexFunc("go 123".as_bytes(), f));
   assert_eq!(2, bytes::LastIndexFunc("123 go".to_string(), f));
   assert_eq!(-1, bytes::LastIndexFunc(vec![b'g',b'o'], f));