fix: path-related bugs

This commit is contained in:
Shunsuke Shibayama 2023-02-25 00:54:11 +09:00
parent e7f1f6894d
commit 50c476b66f
7 changed files with 175 additions and 31 deletions

View file

@ -117,6 +117,16 @@ impl From<&Str> for Str {
}
}
impl From<Cow<'_, str>> for Str {
#[inline]
fn from(s: Cow<'_, str>) -> Self {
match s {
Cow::Borrowed(s) => Str::rc(s),
Cow::Owned(s) => Str::Rc(s.into()),
}
}
}
impl Deref for Str {
type Target = str;
fn deref(&self) -> &Self::Target {
@ -189,6 +199,14 @@ impl Str {
ret
}
pub fn multi_replace(&self, paths: &[(&str, &str)]) -> Self {
let mut self_ = self.to_string();
for (from, to) in paths {
self_ = self_.replace(from, to);
}
Str::rc(&self_)
}
pub fn is_snake_case(&self) -> bool {
self.chars().all(|c| !c.is_uppercase())
}