diff options
author | Adrian Kummerlaender | 2016-04-02 21:44:22 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2016-04-02 21:44:22 +0200 |
commit | 59bfdf3b83119c9e5e29f94362307b7e8a3df43a (patch) | |
tree | 2e5545be0c9eb1c683f28d8ed520baee9a91c11a | |
parent | 78b045924a0b589f599546de7d96b7154f76983e (diff) | |
download | justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar.gz justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar.bz2 justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar.lz justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar.xz justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.tar.zst justify-59bfdf3b83119c9e5e29f94362307b7e8a3df43a.zip |
Add post condition verification and some documentation
-rw-r--r-- | src/line_accumulator.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/line_accumulator.cc b/src/line_accumulator.cc index 36cc370..95c2acd 100644 --- a/src/line_accumulator.cc +++ b/src/line_accumulator.cc @@ -1,5 +1,6 @@ #include "line_accumulator.h" +#include <cassert> #include <iostream> #include <algorithm> @@ -60,18 +61,22 @@ void LineAccumulator::operator()(const std::string& word) { void LineAccumulator::justify() { switch ( this->tokens_.size() ) { + // There is no sensible block justification of null or any single token case 0: case 1: { this->length_ = this->max_length_; break; } + // i.e. left align the first token and right align the second token case 2: { this->tokens_[0].second += this->getMissing(); this->length_ = this->max_length_; break; } + // most common branch for normal texts, add the maximum equal amount of + // spaces to all but the last token default: { const std::uint8_t base = this->getMissing() / (this->tokens_.size() - 2); @@ -89,10 +94,13 @@ void LineAccumulator::justify() { } } + assert(this->getMissing() < this->tokens_.size()); + switch ( this->getMissing() ) { case 0: { break; } + // randomly distribute missing spaces case 1: { this->tokens_[ getRandomIndex(this->random_, this->tokens_.size() - 2) |