From 182ee7816d5bcf794be1f44c6e9224b51567334c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 22 Feb 2021 13:28:45 -0500 Subject: Fixed crash when word is longer than width of terminal --- bible.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bible.cc') diff --git a/bible.cc b/bible.cc index 7c8a89f..87f6659 100644 --- a/bible.cc +++ b/bible.cc @@ -106,7 +106,6 @@ void removeMod(string mod) { libbible::uninstallMod(mod); } -// Stolen from O'Reilly void textWrap(istream& in, ostream& out, size_t width) { string word; string line; @@ -141,8 +140,10 @@ void textWrap(istream& in, ostream& out, size_t width) { //printf("Word: %s, i: %ld\n", word.c_str(), i); if(i > width) { word.erase(0, word.find_first_not_of(" ")); - line.erase(line.find_last_of(" ")); - out << line << '\n'; + if(line.find_last_of(" ") != string::npos) { + line.erase(line.find_last_of(" ")); + out << line << '\n'; + } line = word; } } -- cgit v1.2.3