mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-27 11:59:05 +00:00
fix: path-related bugs
This commit is contained in:
parent
e7f1f6894d
commit
50c476b66f
7 changed files with 175 additions and 31 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue