diff options
Diffstat (limited to 'src/bin/git_remote_nostr/utils.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 3ae1bab..7b5c2d2 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -384,6 +384,20 @@ pub fn error_might_be_authentication_related(error: &anyhow::Error) -> bool { | |||
| 384 | false | 384 | false |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | fn count_lines_per_msg(width: u16, msg: &str, prefix_len: usize) -> usize { | ||
| 388 | if width == 0 { | ||
| 389 | return 1; | ||
| 390 | } | ||
| 391 | // ((msg_len+prefix) / width).ceil() implemented using Integer Arithmetic | ||
| 392 | ((msg.chars().count() + prefix_len) + (width - 1) as usize) / width as usize | ||
| 393 | } | ||
| 394 | |||
| 395 | pub fn count_lines_per_msg_vec(width: u16, msgs: &[String], prefix_len: usize) -> usize { | ||
| 396 | msgs.iter() | ||
| 397 | .map(|msg| count_lines_per_msg(width, msg, prefix_len)) | ||
| 398 | .sum() | ||
| 399 | } | ||
| 400 | |||
| 387 | #[cfg(test)] | 401 | #[cfg(test)] |
| 388 | mod tests { | 402 | mod tests { |
| 389 | use super::*; | 403 | use super::*; |