1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 07:02:29 +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);
}
//delete first and last blank lines from each page
for (uint page=0; page<pages.size(); page++) {
if (pages[page].text.size() > 0) {
//first lines
while (trim(pages[page].text[0]).empty())
pages[page].text.erase(pages[page].text.begin());
//last lines
while (trim(pages[page].text[pages[page].text.size()-1]).empty())
pages[page].text.erase(pages[page].text.end());
}
//delete blank lines at the start and end of each page
for (auto& page : pages) {
//start lines
auto it = page.text.begin();
while (it != page.text.end() &&
it->find_first_not_of(" \t\r") == string::npos) ++it;
page.text.erase(page.text.begin(), it);
//end lines
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());
}
}