diff options
author | Max Kellermann <max@duempel.org> | 2015-01-21 23:43:32 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-01-21 23:43:32 +0100 |
commit | 6cdb2a48961dd606f255bc19bedde79af0bc1d2c (patch) | |
tree | eaac8b58aa08f787e032ac9fe9ea73b896493ee3 /src/fs/io | |
parent | d8bef3270d362c289e89fcb26c91dd6713da1941 (diff) | |
download | mpd-6cdb2a48961dd606f255bc19bedde79af0bc1d2c.tar.gz mpd-6cdb2a48961dd606f255bc19bedde79af0bc1d2c.tar.xz mpd-6cdb2a48961dd606f255bc19bedde79af0bc1d2c.zip |
fs/io/BufferedReader: count line numbers
Replaces the dirty code in config/ConfigFile.cxx.
Diffstat (limited to 'src/fs/io')
-rw-r--r-- | src/fs/io/BufferedReader.cxx | 5 | ||||
-rw-r--r-- | src/fs/io/BufferedReader.hxx | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/fs/io/BufferedReader.cxx b/src/fs/io/BufferedReader.cxx index 01b7b0cf0..9a296d815 100644 --- a/src/fs/io/BufferedReader.cxx +++ b/src/fs/io/BufferedReader.cxx @@ -59,8 +59,10 @@ BufferedReader::ReadLine() { do { char *line = ReadBufferedLine(buffer); - if (line != nullptr) + if (line != nullptr) { + ++line_number; return line; + } } while (Fill(true)); if (last_error.IsDefined() || !eof || buffer.IsEmpty()) @@ -78,5 +80,6 @@ BufferedReader::ReadLine() char *line = buffer.Read().data; buffer.Clear(); + ++line_number; return line; } diff --git a/src/fs/io/BufferedReader.hxx b/src/fs/io/BufferedReader.hxx index 379ea8812..a0c42d23c 100644 --- a/src/fs/io/BufferedReader.hxx +++ b/src/fs/io/BufferedReader.hxx @@ -41,9 +41,12 @@ class BufferedReader { bool eof; + unsigned line_number; + public: BufferedReader(Reader &_reader) - :reader(_reader), buffer(4096), eof(false) {} + :reader(_reader), buffer(4096), eof(false), + line_number(0) {} gcc_pure bool Check() const { @@ -70,6 +73,10 @@ public: } char *ReadLine(); + + unsigned GetLineNumber() const { + return line_number; + } }; #endif |