aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-04-22 22:23:35 +0200
committerAdrian Kummerlaender2016-04-22 22:23:35 +0200
commit5eb3689c9985f28b46651f547b9b32d55b4a07b5 (patch)
tree798b747b241de9f9233fa7b5dc6ce96a2fbbcde5
parentb647d08bb19abe4d199166a05f9f14c65f5f0ed4 (diff)
downloadjustify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar.gz
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar.bz2
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar.lz
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar.xz
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.tar.zst
justify-5eb3689c9985f28b46651f547b9b32d55b4a07b5.zip
Handle input stream EOF
-rw-r--r--justify.cc8
-rw-r--r--src/line_accumulator.cc2
2 files changed, 7 insertions, 3 deletions
diff --git a/justify.cc b/justify.cc
index 8120ded..c417dfd 100644
--- a/justify.cc
+++ b/justify.cc
@@ -81,8 +81,12 @@ bool process(const boost::program_options::variables_map& variables) {
justify::LineAccumulator acc{line_length, line_offset};
std::string token;
- while ( std::cin >> token ) {
- acc(token);
+ while ( std::cin.good() ) {
+ if ( std::cin >> token ) {
+ acc(token);
+ } else {
+ return true;
+ }
}
return true;
diff --git a/src/line_accumulator.cc b/src/line_accumulator.cc
index 4398c50..9ce389b 100644
--- a/src/line_accumulator.cc
+++ b/src/line_accumulator.cc
@@ -149,7 +149,7 @@ void LineAccumulator::justify() {
std::for_each(
indizes.begin(),
indizes.begin() + this->getMissing(),
- [&](std::uint8_t x) {
+ [&](const std::uint8_t x) {
this->tokens_[x].second += 1;
this->length_ += 1;
}