Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Commit

Permalink
replaced split_line with a multibyte aware version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronnybremer authored Jan 27, 2024
1 parent 7f93147 commit a92678d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/generator/ical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ fn get_value(value: &Option<String>) -> String {
}

pub(crate) fn split_line<T: Into<String>>(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::<String>())
.take_while(|s| !s.is_empty())
.collect::<Vec<_>>();
sub_string.join("\r\n ")
}

//
Expand Down

0 comments on commit a92678d

Please sign in to comment.