File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,23 @@ impl BStr {
31
31
// SAFETY: `BStr` is transparent to `[u8]`.
32
32
unsafe { & * ( bytes as * const [ u8 ] as * const BStr ) }
33
33
}
34
+
35
+ /// Strip a prefix from `self`. Delegates to [`slice::strip_prefix`].
36
+ ///
37
+ /// # Examples
38
+ ///
39
+ /// ```
40
+ /// # use kernel::b_str;
41
+ /// assert_eq!(Some(b_str!("bar")), b_str!("foobar").strip_prefix(b_str!("foo")));
42
+ /// assert_eq!(None, b_str!("foobar").strip_prefix(b_str!("bar")));
43
+ /// assert_eq!(Some(b_str!("foobar")), b_str!("foobar").strip_prefix(b_str!("")));
44
+ /// assert_eq!(Some(b_str!("")), b_str!("foobar").strip_prefix(b_str!("foobar")));
45
+ /// ```
46
+ pub fn strip_prefix ( & self , pattern : impl AsRef < Self > ) -> Option < & BStr > {
47
+ self . deref ( )
48
+ . strip_prefix ( pattern. as_ref ( ) . deref ( ) )
49
+ . map ( Self :: from_bytes)
50
+ }
34
51
}
35
52
36
53
impl fmt:: Display for BStr {
You can’t perform that action at this time.
0 commit comments