Refactor read_fd '\r' removal logic
This commit is contained in:
parent
ac91a79b12
commit
cf37623f1a
12
src/file.cc
12
src/file.cc
|
@ -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};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user