From 444eef557e223b2c0c2563ff7773f7c0ecb51d00 Mon Sep 17 00:00:00 2001 From: Pavlo Rudyi Date: Fri, 9 Oct 2020 20:54:26 +0000 Subject: [PATCH] improve handling the long utf8 tracks --- src/audio/player.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/audio/player.rs b/src/audio/player.rs index 7074f6c7..b4c9a6ed 100644 --- a/src/audio/player.rs +++ b/src/audio/player.rs @@ -389,9 +389,11 @@ impl SongTitle { // Remove unsupported characters from the file name let title_raw = utils::simplify_string(title.to_string()); // Limit file name to 200 chars - let title_vec = title_raw.chars().collect::>(); - let cut_to_length = title_vec.len().min(200); - let title = title_vec[..cut_to_length].iter().cloned().collect::(); + let mut limit = 200; + while (title_raw.len() > 200) && (!title_raw.is_char_boundary(limit)) { + limit -= 1; + } + let title = &title_raw[..limit.min(title_raw.len())]; let mut path = path::CACHE.clone(); path.push("recording"); -- GitLab