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) if (text)
{ {
ssize_t beg = 0; for (StringView data{buf, buf + size}; not data.empty();)
for (ssize_t pos = 0; pos < size; ++pos)
{ {
if (buf[pos] == '\r') auto it = find(data, '\r');
{ content += StringView{data.begin(), it};
content += StringView{buf + beg, buf + pos}; data = StringView{(it != data.end()) ? it+1 : it, data.end()};
beg = pos + 1;
}
} }
content += StringView{buf + beg, buf + size};
} }
else else
content += StringView{buf, buf + size}; content += StringView{buf, buf + size};