(line: &str, width: usize)
| 244 | } |
| 245 | |
| 246 | fn wrap_cell_line(line: &str, width: usize) -> Vec<String> { |
| 247 | if line.split_whitespace().count() <= 1 { |
| 248 | return vec![truncate_visible(line, width)]; |
| 249 | } |
| 250 | |
| 251 | let mut lines = Vec::new(); |
| 252 | let mut current = String::new(); |
| 253 | for word in line.split_whitespace() { |
| 254 | let candidate_width = if current.is_empty() { |
| 255 | visible_width(word) |
| 256 | } else { |
| 257 | visible_width(¤t) + 1 + visible_width(word) |
| 258 | }; |
| 259 | if candidate_width <= width { |
| 260 | if !current.is_empty() { |
| 261 | current.push(' '); |
| 262 | } |
| 263 | current.push_str(word); |
| 264 | } else { |
| 265 | if !current.is_empty() { |
| 266 | lines.push(current); |
| 267 | } |
| 268 | current = if visible_width(word) > width { |
| 269 | truncate_visible(word, width) |
| 270 | } else { |
| 271 | word.to_string() |
| 272 | }; |
| 273 | } |
| 274 | } |
| 275 | if !current.is_empty() { |
| 276 | lines.push(current); |
| 277 | } |
| 278 | lines |
| 279 | } |
| 280 | |
| 281 | fn truncate_visible(value: &str, width: usize) -> String { |
| 282 | if visible_width(value) <= width { |
no test coverage detected