From 203786726bcdbd50e0df4ec539f7b7fcae81c577 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 10 May 2021 15:19:06 +0900 Subject: [PATCH] Bug fixes for C++ impl --- cpp_impl/src/helpers.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp_impl/src/helpers.cpp b/cpp_impl/src/helpers.cpp index daca483..efc0479 100644 --- a/cpp_impl/src/helpers.cpp +++ b/cpp_impl/src/helpers.cpp @@ -130,9 +130,12 @@ void Helpers::printGreedyTextJustification(unsigned long long width, const std:: std::vector currentLine; unsigned long long currentToken = 0; unsigned long long size = 0; - while(true) { + while(currentToken < tokens.size()) { size += tokens.at(currentToken).size(); if(size + 1 >= width) { + if(currentLine.empty()) { + currentLine.push_back(tokens.at(currentToken++)); + } printCurrentLine(currentLine); size = 0; continue; @@ -140,9 +143,6 @@ void Helpers::printGreedyTextJustification(unsigned long long width, const std:: currentLine.push_back(tokens.at(currentToken)); size += 1; ++currentToken; - if(currentToken >= tokens.size()) { - break; - } } } if(!currentLine.empty()) {