This commit is contained in:
euzu
2025-07-08 18:23:03 +02:00
parent 2f26468499
commit b65eb87417
30 changed files with 399 additions and 121 deletions
+19
View File
@@ -1,3 +1,5 @@
use std::borrow::Cow;
pub trait Capitalize {
fn capitalize(&self) -> String;
}
@@ -63,6 +65,23 @@ pub fn get_non_empty_str<'a>(first: &'a str, second: &'a str, third: &'a str) ->
}
}
pub fn trim_slash(s: &str) -> Cow<str> {
let trimmed = s.trim_matches('/');
if trimmed.len() == s.len() {
Cow::Borrowed(s) // Keine Änderung → kein Clone
} else {
Cow::Owned(trimmed.to_string()) // Änderung → neue String
}
}
pub fn trim_last_slash(s: &str) -> Cow<str> {
if s.ends_with('/') {
Cow::Owned(s[..s.len() - 1].to_string())
} else {
Cow::Borrowed(s)
}
}
#[cfg(test)]
mod test {
use std::collections::HashSet;