Cleanup compute_needed_size implementation

This commit is contained in:
Maxime Coste 2015-09-23 00:43:40 +01:00
parent eed3e5459d
commit 6ec693d598

View File

@ -721,17 +721,15 @@ void NCursesUI::menu_hide()
static CharCoord compute_needed_size(StringView str) static CharCoord compute_needed_size(StringView str)
{ {
using Utf8Iterator = utf8::iterator<const char*, utf8::InvalidPolicy::Pass>;
CharCoord res{1,0}; CharCoord res{1,0};
CharCount line_len = 0; CharCount line_len = 0;
for (Utf8Iterator begin{str.begin()}, end{str.end()}; for (auto it = str.begin(), end = str.end();
begin != end; ++begin) it != end; it = utf8::next(it, end))
{ {
if (*begin == '\n') if (*it == '\n')
{ {
// ignore last '\n', no need to show an empty line // ignore last '\n', no need to show an empty line
if (begin+1 == end) if (it+1 == end)
break; break;
res.column = max(res.column, line_len); res.column = max(res.column, line_len);