From a92678d32c21cd2827f3999a16d9752329423475 Mon Sep 17 00:00:00 2001 From: Ronny Bremer Date: Sat, 27 Jan 2024 15:58:44 +0100 Subject: [PATCH] replaced split_line with a multibyte aware version split_line was working fine as long as the input was just plain US-ASCII. When using multibyte characters and they happened to be at the end of the line to spit the function did panic. The new code returns correctly split lines even if they contain multibyte characters. --- src/generator/ical.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generator/ical.rs b/src/generator/ical.rs index 0c5288e..68fefde 100644 --- a/src/generator/ical.rs +++ b/src/generator/ical.rs @@ -19,13 +19,13 @@ fn get_value(value: &Option) -> String { } pub(crate) fn split_line>(str: T) -> String { - let mut str = str.into(); - let mut x = 75; - while x < str.len() { - str.insert_str(x, "\r\n "); - x += 77; - } - str + let str = str.into(); + let mut chars = str.chars(); + let sub_string = (0..) + .map(|_| chars.by_ref().take(75).collect::()) + .take_while(|s| !s.is_empty()) + .collect::>(); + sub_string.join("\r\n ") } //