Skip to content

Commit

Permalink
fix: replace duplicated code with trim functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hozarho committed Nov 17, 2024
1 parent e47adc6 commit 2404192
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions jellyfin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ impl Client {
}

fn sanitize_display_format(input: &str) -> String {
let mut result = input.trim().to_string();
let mut result = input.to_string();

result = result.trim().to_string();

// Remove unnecessary spaces
while result.contains(" ") {
Expand All @@ -364,17 +366,13 @@ impl Client {
}

// Remove unnecessary separators
while result.starts_with(" {sep}") {
result = result.drain(6..).collect();
}
while result.starts_with("{sep}") {
result = result.drain(5..).collect();
}
while result.ends_with(" {sep}") {
result = result.drain(..result.len() - 6).collect();
result = result.trim_start().to_string();
}
while result.ends_with("{sep}") {
result = result.drain(..result.len() - 5).collect();
result = result.trim_end().to_string();
}

result
Expand Down

0 comments on commit 2404192

Please sign in to comment.