mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 12:46:49 +00:00
add str traits for split, between, unquote; consolidate tests
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
2db017af37
commit
99ad404ea9
8 files changed
+212
-51
No files matched your search
@@ -0,0 +1,22 @@
|
||||
use super::EMPTY;
|
||||
|
||||
type Pair<'a> = (&'a str, &'a str);
|
||||
|
||||
/// Split a string with default behaviors on non-match.
|
||||
pub trait SplitInfallible<'a> {
|
||||
/// Split a string at the first occurrence of delim. If not found, the
|
||||
/// entire string is returned in \[0\], while \[1\] is empty.
|
||||
fn split_once_infallible(&self, delim: &str) -> Pair<'a>;
|
||||
|
||||
/// Split a string from the last occurrence of delim. If not found, the
|
||||
/// entire string is returned in \[0\], while \[1\] is empty.
|
||||
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a>;
|
||||
}
|
||||
|
||||
impl<'a> SplitInfallible<'a> for &'a str {
|
||||
#[inline]
|
||||
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a> { self.rsplit_once(delim).unwrap_or((self, EMPTY)) }
|
||||
|
||||
#[inline]
|
||||
fn split_once_infallible(&self, delim: &str) -> Pair<'a> { self.split_once(delim).unwrap_or((self, EMPTY)) }
|
||||
}
|
||||
Reference in new issue
Block a user