Refactor read_fd '\r' removal logic

This commit is contained in:
Maxime Coste 2018-03-18 23:42:17 +11:00
parent ac91a79b12
commit cf37623f1a

View File

@ -166,16 +166,12 @@ String read_fd(int fd, bool text)
if (text)
{
ssize_t beg = 0;
for (ssize_t pos = 0; pos < size; ++pos)
for (StringView data{buf, buf + size}; not data.empty();)
{
if (buf[pos] == '\r')
{
content += StringView{buf + beg, buf + pos};
beg = pos + 1;
}
auto it = find(data, '\r');
content += StringView{data.begin(), it};
data = StringView{(it != data.end()) ? it+1 : it, data.end()};
}
content += StringView{buf + beg, buf + size};
}
else
content += StringView{buf, buf + size};