Simple word-wrap for the description block.
(text: &str, width: usize)
| 552 | |
| 553 | /// Simple word-wrap for the description block. |
| 554 | fn wrap(text: &str, width: usize) -> Vec<String> { |
| 555 | let mut out: Vec<String> = vec![]; |
| 556 | for paragraph in text.split('\n') { |
| 557 | let mut line = String::new(); |
| 558 | for word in paragraph.split_whitespace() { |
| 559 | if line.is_empty() { |
| 560 | line.push_str(word); |
| 561 | } else if line.len() + 1 + word.len() <= width { |
| 562 | line.push(' '); |
| 563 | line.push_str(word); |
| 564 | } else { |
| 565 | out.push(line.clone()); |
| 566 | line.clear(); |
| 567 | line.push_str(word); |
| 568 | } |
| 569 | } |
| 570 | if !line.is_empty() { |
| 571 | out.push(line); |
| 572 | } |
| 573 | } |
| 574 | if out.is_empty() { |
| 575 | out.push(String::new()); |
| 576 | } |
| 577 | out |
| 578 | } |
| 579 | |
| 580 | #[cfg(test)] |
| 581 | mod tests { |
no outgoing calls
no test coverage detected
searching dependent graphs…