use alloc::string::String;
pub fn delete_end_backslash<'a, S: ?Sized + AsRef<str> + 'a>(s: &'a S) -> &'a str {
let s = s.as_ref();
let length = s.len();
if length > 1 && s.ends_with('\\') {
return &s[..length - 1];
} else {
return s;
}
}
pub fn delete_end_backslash_owned<S: Into<String>>(s: S) -> String {
let mut s = s.into();
let length = s.len();
if length > 1 && s.ends_with('\\') {
s.remove(length - 1);
}
return s;
}
pub fn delete_end_backslash_mut(s: &mut String) {
let length = s.len();
if length > 1 && s.ends_with('\\') {
s.remove(length - 1);
}
}
pub fn delete_start_backslash<'a, S: ?Sized + AsRef<str> + 'a>(s: &'a S) -> &'a str {
let s = s.as_ref();
let length = s.len();
if length > 1 && s.starts_with('\\') {
return &s[1..];
} else {
return s;
}
}
pub fn delete_start_backslash_owned<S: Into<String>>(s: S) -> String {
let mut s = s.into();
let length = s.len();
if length > 1 && s.starts_with('\\') {
s.remove(0);
}
return s;
}
pub fn delete_start_backslash_mut(s: &mut String) {
let length = s.len();
if length > 1 && s.starts_with('\\') {
s.remove(0);
}
}
pub fn add_start_backslash<S: AsRef<str>>(s: S) -> String {
add_start_backslash_owned(s.as_ref())
}
pub fn add_start_backslash_owned<S: Into<String>>(s: S) -> String {
let mut s = s.into();
if !s.starts_with('\\') {
s.insert(0, '\\');
}
return s;
}
pub fn add_start_backslash_mut(s: &mut String) {
if !s.starts_with('\\') {
s.insert(0, '\\');
}
}
pub fn add_end_backslash<S: AsRef<str>>(s: S) -> String {
add_end_backslash_owned(s.as_ref())
}
pub fn add_end_backslash_owned<S: Into<String>>(s: S) -> String {
let mut s = s.into();
if !s.ends_with('\\') {
s.push('\\');
}
return s;
}
pub fn add_end_backslash_mut(s: &mut String) {
if !s.ends_with('\\') {
s.push('\\');
}
}
pub fn concat_with_backslash<S1: AsRef<str>, S2: AsRef<str>>(s1: S1, s2: S2) -> String {
concat_with_backslash_owned(s1.as_ref(), s2)
}
pub fn concat_with_backslash_owned<S1: Into<String>, S2: AsRef<str>>(s1: S1, s2: S2) -> String {
return delete_end_backslash_owned(add_end_backslash_owned(s1) + delete_start_backslash(s2.as_ref()));
}
pub fn concat_with_backslash_mut<S2: AsRef<str>>(s1: &mut String, s2: S2) {
add_end_backslash_mut(s1);
s1.push_str(delete_start_backslash(s2.as_ref()));
delete_end_backslash_mut(s1);
}
#[macro_export]
macro_rules! concat_with_backslash {
($s:expr, $($sc:expr), *) => {
{
let mut s = $s.to_owned();
$(
::slash_formatter::concat_with_backslash_mut(&mut s, $sc);
)*
s
}
};
}
#[macro_export]
macro_rules! concat_with_backslash_mut {
($s:expr, $($sc:expr), *) => {
{
$(
::slash_formatter::concat_with_backslash_mut($s, $sc);
)*
}
};
}