add str traits for split, between, unquote; consolidate tests

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-08-31 02:13:23 +00:00 committed by strawberry
parent 2db017af37
commit 99ad404ea9
8 changed files with 212 additions and 51 deletions

View file

@ -1,3 +1,10 @@
mod between;
mod split;
mod tests;
mod unquote;
mod unquoted;
pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::Unquoted};
use crate::{utils::exchange, Result};
pub const EMPTY: &str = "";
@ -95,12 +102,6 @@ pub fn common_prefix<'a>(choice: &'a [&str]) -> &'a str {
})
}
#[inline]
#[must_use]
pub fn split_once_infallible<'a>(input: &'a str, delim: &'_ str) -> (&'a str, &'a str) {
input.split_once(delim).unwrap_or((input, EMPTY))
}
/// Parses the bytes into a string.
pub fn string_from_bytes(bytes: &[u8]) -> Result<String> {
let str: &str = str_from_bytes(bytes)?;