From d111d07ec22e0af5db807cb1ba05dd78bd3384fa Mon Sep 17 00:00:00 2001 From: ClementTsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 24 Nov 2023 03:03:44 -0500 Subject: [PATCH] update comments --- src/utils/gen_util.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs index effd5a6bc..e423b6b2d 100644 --- a/src/utils/gen_util.rs +++ b/src/utils/gen_util.rs @@ -102,11 +102,14 @@ fn truncate_str>(content: &str, width: U) -> String { let width = width.into(); if content.len() <= width { - // If the entire string fits in the width, it'll definitely fit. + // If the entire string fits in the width, then we just + // need to copy the entire string over. + content.to_owned() } else if width > 0 { if content.is_ascii() { - // If the entire string is ASCII, we can use a much simpler approach. + // If the entire string is ASCII, we can use a much simpler approach + // in regards to what we truncate. let mut text = String::with_capacity(width); let (keep, _throw) = content.split_at(width - 1); @@ -115,6 +118,9 @@ fn truncate_str>(content: &str, width: U) -> String { text } else { + // Otherwise iterate by grapheme and greedily fit as many graphemes + // as width will allow. + let mut text = String::with_capacity(width); let mut curr_width = 0; let mut early_break = false;