FieldsFunc

Function FieldsFunc 

Source
pub fn FieldsFunc(s: &[byte], f: fn(rune) -> bool) -> Vec<&[byte]>
Expand description

FieldsFunc interprets s as a sequence of UTF-8-encoded code points. It splits the slice s at each run of code points c satisfying f(c) and returns a slice of subslices of s. If all code points in s satisfy f(c), or len(s) == 0, an empty slice is returned.

FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.

zh-cn 类似Fields,但使用函数f来确定分割符(满足f的utf-8码值)。如果字符串全部是分隔符或者是空字符串的话,会返回空切片。

§Example

use gostd_bytes as bytes;

   /* fn f(c: u32) -> bool {
       let s = char::from_u32(c).unwrap();
       !s.is_numeric() && !s.is_alphabetic()
   } */
   // f 用函数或者匿名函数都可以
   let f = |c: u32| {
       let s = char::from_u32(c).unwrap();
       !s.is_numeric() && !s.is_alphabetic()
   };
   assert_eq!(
       vec!["foo1".as_bytes(), "bar2".as_bytes(), "baz3".as_bytes()],
       bytes::FieldsFunc("  foo1;bar2,baz3...".as_bytes(), f)
   )