fix: Stop revhex on EOF

This commit is contained in:
teor 2020-07-15 17:10:28 +10:00
parent d8834b149a
commit 78459afe97
1 changed files with 4 additions and 1 deletions

View File

@ -36,7 +36,10 @@ impl Runnable for RevhexCmd {
if self.input.is_empty() || self.input == "-" { if self.input.is_empty() || self.input == "-" {
// "-" is a typical command-line argument for "read standard input" // "-" is a typical command-line argument for "read standard input"
let mut input = String::new(); let mut input = String::new();
while stdin().read_line(&mut input).is_ok() { // Unlike similar C APIs, read_line returns Ok(0) on EOF.
// We can distinguish EOF from an empty line, because the newline is
// included in the buffer, so empty lines return Ok(1).
while stdin().read_line(&mut input).unwrap_or(0) > 0 {
println!("{}", byte_reverse_hex(&input.trim())); println!("{}", byte_reverse_hex(&input.trim()));
} }
} else { } else {