mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 11:36:16 +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
22
src/font.cpp
22
src/font.cpp
@ -76,21 +76,19 @@ int Font::getTextWidth(const string &text)
|
|||||||
|
|
||||||
string Font::wordWrap(const string &text, int width)
|
string Font::wordWrap(const string &text, int width)
|
||||||
{
|
{
|
||||||
|
const size_t len = text.length();
|
||||||
string result;
|
string result;
|
||||||
result.reserve(text.length());
|
result.reserve(len);
|
||||||
|
|
||||||
size_t start = 0, end = text.find('\n');
|
size_t start = 0;
|
||||||
while (end != string::npos) {
|
while (true) {
|
||||||
if (start != end) {
|
size_t end = min(text.find('\n', start), len);
|
||||||
result.append(wordWrapSingleLine(text, start, end, width));
|
result.append(wordWrapSingleLine(text, start, end, width));
|
||||||
}
|
|
||||||
result.append("\n");
|
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
end = text.find('\n', start);
|
if (start >= len) {
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
if (start < text.length()) {
|
result.push_back('\n');
|
||||||
result.append(wordWrapSingleLine(text, start, text.length(), width));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user