| 1 |
use std::error::Error; |
| 2 |
use std::io::{self, BufRead, Write}; |
| 3 |
|
| 4 |
use unicode_segmentation::UnicodeSegmentation; |
| 5 |
|
| 6 |
fn main() -> Result<(), Box<dyn Error>> { |
| 7 |
let stdin = io::stdin(); |
| 8 |
let mut stdin = stdin.lock(); |
| 9 |
let mut stdout = io::BufWriter::new(io::stdout()); |
| 10 |
|
| 11 |
let mut line = String::new(); |
| 12 |
while stdin.read_line(&mut line)? > 0 { |
| 13 |
let end = line |
| 14 |
.grapheme_indices(true) |
| 15 |
.map(|(start, g)| start + g.len()) |
| 16 |
.take(10) |
| 17 |
.last() |
| 18 |
.unwrap_or(line.len()); |
| 19 |
stdout.write_all(line[..end].trim_end().as_bytes())?; |
| 20 |
stdout.write_all(b"\n")?; |
| 21 |
|
| 22 |
line.clear(); |
| 23 |
} |
| 24 |
Ok(()) |
| 25 |
} |