mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 11:46:14 +02:00
Changed word wrapping to avoid trailing empty line
If a text file ends in a newline, the previous line splitting code would append an empty line at the end, which looked odd. So now we explicitly check that a newline is only inserted if more characters follow.
This commit is contained in:
parent
bac622fc39
commit
e44db20f31
18
src/font.cpp
18
src/font.cpp
@ -76,21 +76,19 @@ int Font::getTextWidth(const string &text)
|
||||
|
||||
string Font::wordWrap(const string &text, int width)
|
||||
{
|
||||
const size_t len = text.length();
|
||||
string result;
|
||||
result.reserve(text.length());
|
||||
result.reserve(len);
|
||||
|
||||
size_t start = 0, end = text.find('\n');
|
||||
while (end != string::npos) {
|
||||
if (start != end) {
|
||||
size_t start = 0;
|
||||
while (true) {
|
||||
size_t end = min(text.find('\n', start), len);
|
||||
result.append(wordWrapSingleLine(text, start, end, width));
|
||||
}
|
||||
result.append("\n");
|
||||
start = end + 1;
|
||||
end = text.find('\n', start);
|
||||
if (start >= len) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (start < text.length()) {
|
||||
result.append(wordWrapSingleLine(text, start, text.length(), width));
|
||||
result.push_back('\n');
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user