summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-11-20 18:45:10 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-11-20 18:45:10 +0000
commitb5ccc8bc73f0d2e3916a51837d9a8b699127944c (patch)
treed3c0c1573fa4a20c67fdf4937b8d78898dc44f64 /src
parent04ecb2cc5ae9cd860d6a1e697e362e9d1f34049d (diff)
Improve line wrapping behaviour
Diffstat (limited to 'src')
-rw-r--r--src/string.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/string.cc b/src/string.cc
index 2b453abd..1313448c 100644
--- a/src/string.cc
+++ b/src/string.cc
@@ -155,8 +155,8 @@ std::vector<StringView> wrap_lines(StringView text, CharCount max_width)
Utf8It end{text.end()};
CharCount col = 0;
std::vector<StringView> lines;
- const char* line_begin = text.begin();
- const char* line_end = line_begin;
+ Utf8It line_begin = text.begin();
+ Utf8It line_end = line_begin;
while (word_begin != end)
{
const CharCategories cat = categorize(*word_begin);
@@ -166,21 +166,21 @@ std::vector<StringView> wrap_lines(StringView text, CharCount max_width)
} while (word_end != end and categorize(*word_end) == cat);
col += word_end - word_begin;
- if (col > max_width or cat == CharCategories::EndOfLine)
+ if ((word_begin != line_begin and col > max_width) or
+ cat == CharCategories::EndOfLine)
{
- lines.emplace_back(line_begin, line_end);
+ lines.emplace_back(line_begin.base(), line_end.base());
line_begin = (cat == CharCategories::EndOfLine or
- cat == CharCategories::Blank) ? word_end.base()
- : word_begin.base();
- col = word_end - Utf8It{line_begin};
+ cat == CharCategories::Blank) ? word_end : word_begin;
+ col = word_end - line_begin;
}
if (cat == CharCategories::Word or cat == CharCategories::Punctuation)
- line_end = word_end.base();
+ line_end = word_end;
word_begin = word_end;
}
- if (line_begin != word_begin.base())
- lines.emplace_back(line_begin, word_begin.base());
+ if (line_begin != word_begin)
+ lines.emplace_back(line_begin.base(), word_begin.base());
return lines;
}