1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 11:46:14 +02:00

Rewrote empty line stripping in manual display

The original code was incorrect: it used erase() on the end() iterator.
Also, it only checked for an initially empty page, but could not deal
with a page containing only empty lines, which will become an empty
page during the empty line removal.

The check for a line being empty is now done by searching the line for
non-whitespace characters instead of by trimming it. This avoids
creating new string objects that are only used to check whether they
are empty.
This commit is contained in:
Maarten ter Huurne 2014-09-17 14:26:51 +02:00
parent 4997438c11
commit a03f8957aa

View File

@ -54,16 +54,18 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
pages.push_back(mp); pages.push_back(mp);
} }
//delete first and last blank lines from each page //delete blank lines at the start and end of each page
for (uint page=0; page<pages.size(); page++) { for (auto& page : pages) {
if (pages[page].text.size() > 0) { //start lines
//first lines auto it = page.text.begin();
while (trim(pages[page].text[0]).empty()) while (it != page.text.end() &&
pages[page].text.erase(pages[page].text.begin()); it->find_first_not_of(" \t\r") == string::npos) ++it;
//last lines page.text.erase(page.text.begin(), it);
while (trim(pages[page].text[pages[page].text.size()-1]).empty()) //end lines
pages[page].text.erase(pages[page].text.end()); it = page.text.end();
} while (it != page.text.begin() &&
(it - 1)->find_first_not_of(" \t\r") == string::npos) --it;
page.text.erase(it, page.text.end());
} }
} }