aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/TextInputStream.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-07 00:06:02 +0200
committerMax Kellermann <max@duempel.org>2014-08-07 00:06:02 +0200
commit69ae879c585039297951821e353f7c1ca12b6cb8 (patch)
treefe394a053d2a45817e934f926be6ee660ba689a8 /src/input/TextInputStream.cxx
parent08fee9a284cc082822392b38574fd2d4b0afb843 (diff)
downloadmpd-69ae879c585039297951821e353f7c1ca12b6cb8.tar.gz
mpd-69ae879c585039297951821e353f7c1ca12b6cb8.tar.xz
mpd-69ae879c585039297951821e353f7c1ca12b6cb8.zip
input/TextInputStream: return char*
Revert to the old API before commit e9e55b08, removing unnecessary bloat.
Diffstat (limited to 'src/input/TextInputStream.cxx')
-rw-r--r--src/input/TextInputStream.cxx25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/input/TextInputStream.cxx b/src/input/TextInputStream.cxx
index d7cb440b3..b90eeacc0 100644
--- a/src/input/TextInputStream.cxx
+++ b/src/input/TextInputStream.cxx
@@ -27,9 +27,10 @@
#include <assert.h>
#include <string.h>
-bool TextInputStream::ReadLine(std::string &line)
+char *
+TextInputStream::ReadLine()
{
- const char *src, *p;
+ char *src, *p;
do {
size_t nbytes;
@@ -46,33 +47,33 @@ bool TextInputStream::ReadLine(std::string &line)
buffer.Append(nbytes);
else if (error.IsDefined()) {
LogError(error);
- return false;
+ return nullptr;
}
} else
nbytes = 0;
auto src_p = buffer.Read();
if (src_p.IsEmpty())
- return false;
+ return nullptr;
src = src_p.data;
- p = reinterpret_cast<const char*>(memchr(src, '\n', src_p.size));
+ p = reinterpret_cast<char*>(memchr(src, '\n', src_p.size));
if (p == nullptr && nbytes == 0) {
/* end of file (or line too long): terminate
the current line */
dest = buffer.Write();
assert(!dest.IsEmpty());
- dest[0] = '\n';
- buffer.Append(1);
+ dest[0] = 0;
+ buffer.Clear();
+ return src;
}
} while (p == nullptr);
- size_t length = p - src + 1;
+ buffer.Consume(p - src + 1);
+
while (p > src && IsWhitespaceOrNull(p[-1]))
--p;
-
- line = std::string(src, p - src);
- buffer.Consume(length);
- return true;
+ *p = 0;
+ return src;
}