mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 06:54:05 +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:
parent
4997438c11
commit
a03f8957aa
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user