fs/io/BufferedReader: count line numbers
Replaces the dirty code in config/ConfigFile.cxx.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user