aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input/TextInputStream.cxx25
-rw-r--r--src/input/TextInputStream.hxx8
-rw-r--r--src/playlist/plugins/CuePlaylistPlugin.cxx6
-rw-r--r--src/playlist/plugins/ExtM3uPlaylistPlugin.cxx11
-rw-r--r--src/playlist/plugins/M3uPlaylistPlugin.cxx5
5 files changed, 24 insertions, 31 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;
}
diff --git a/src/input/TextInputStream.hxx b/src/input/TextInputStream.hxx
index 873ecdbda..6f39d22cf 100644
--- a/src/input/TextInputStream.hxx
+++ b/src/input/TextInputStream.hxx
@@ -22,8 +22,6 @@
#include "util/StaticFifoBuffer.hxx"
-#include <string>
-
class InputStream;
class TextInputStream {
@@ -46,11 +44,9 @@ public:
/**
* Reads the next line from the stream with newline character stripped.
*
- * @param line a string to put result to
- * @return true if line is read successfully, false on end of file
- * or error
+ * @return a pointer to the line, or nullptr on end-of-file or error
*/
- bool ReadLine(std::string &line);
+ char *ReadLine();
};
#endif
diff --git a/src/playlist/plugins/CuePlaylistPlugin.cxx b/src/playlist/plugins/CuePlaylistPlugin.cxx
index 8776baace..b907d34d0 100644
--- a/src/playlist/plugins/CuePlaylistPlugin.cxx
+++ b/src/playlist/plugins/CuePlaylistPlugin.cxx
@@ -52,9 +52,9 @@ CuePlaylist::NextSong()
if (song != nullptr)
return song;
- std::string line;
- while (tis.ReadLine(line)) {
- parser.Feed(line.c_str());
+ const char *line;
+ while ((line = tis.ReadLine()) != nullptr) {
+ parser.Feed(line);
song = parser.Get();
if (song != nullptr)
return song;
diff --git a/src/playlist/plugins/ExtM3uPlaylistPlugin.cxx b/src/playlist/plugins/ExtM3uPlaylistPlugin.cxx
index 5dd127add..95cc84289 100644
--- a/src/playlist/plugins/ExtM3uPlaylistPlugin.cxx
+++ b/src/playlist/plugins/ExtM3uPlaylistPlugin.cxx
@@ -39,9 +39,8 @@ public:
}
bool CheckFirstLine() {
- std::string line;
- return tis.ReadLine(line) &&
- strcmp(line.c_str(), "#EXTM3U") == 0;
+ const char *line = tis.ReadLine();
+ return line != nullptr && strcmp(line, "#EXTM3U") == 0;
}
virtual DetachedSong *NextSong() override;
@@ -105,15 +104,13 @@ DetachedSong *
ExtM3uPlaylist::NextSong()
{
Tag tag;
- std::string line;
const char *line_s;
do {
- if (!tis.ReadLine(line))
+ line_s = tis.ReadLine();
+ if (line_s == nullptr)
return nullptr;
- line_s = line.c_str();
-
if (StringStartsWith(line_s, "#EXTINF:")) {
tag = extm3u_parse_tag(line_s + 8);
continue;
diff --git a/src/playlist/plugins/M3uPlaylistPlugin.cxx b/src/playlist/plugins/M3uPlaylistPlugin.cxx
index f892f2010..c7f3b5085 100644
--- a/src/playlist/plugins/M3uPlaylistPlugin.cxx
+++ b/src/playlist/plugins/M3uPlaylistPlugin.cxx
@@ -45,14 +45,13 @@ m3u_open_stream(InputStream &is)
DetachedSong *
M3uPlaylist::NextSong()
{
- std::string line;
const char *line_s;
do {
- if (!tis.ReadLine(line))
+ line_s = tis.ReadLine();
+ if (line_s == nullptr)
return nullptr;
- line_s = line.c_str();
line_s = strchug_fast(line_s);
} while (line_s[0] == '#' || *line_s == 0);