aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-02-22 13:28:45 -0500
committerYour Name <you@example.com>2021-02-22 13:28:45 -0500
commit182ee7816d5bcf794be1f44c6e9224b51567334c (patch)
tree4cd723f57838588c7180a80aa97167b89e9afec6
parent79e349890265b2ba64de0fc29efa588586785b89 (diff)
downloadlibbible-182ee7816d5bcf794be1f44c6e9224b51567334c.tar.gz
libbible-182ee7816d5bcf794be1f44c6e9224b51567334c.tar.bz2
libbible-182ee7816d5bcf794be1f44c6e9224b51567334c.zip
Fixed crash when word is longer than width of terminal
-rw-r--r--bible.cc7
1 files changed, 4 insertions, 3 deletions
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;
}
}