From 2404192860c156fc047ddc00223dbed8fa60393a Mon Sep 17 00:00:00 2001 From: hozarho Date: Sun, 17 Nov 2024 14:44:35 +0100 Subject: [PATCH] fix: replace duplicated code with trim functions --- jellyfin-rpc/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/jellyfin-rpc/src/lib.rs b/jellyfin-rpc/src/lib.rs index 576a0ec..f8a632b 100644 --- a/jellyfin-rpc/src/lib.rs +++ b/jellyfin-rpc/src/lib.rs @@ -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(" ") { @@ -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