1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CRAZY_LINKER_LINE_READER_H
6 #define CRAZY_LINKER_LINE_READER_H
10 #include "crazy_linker_system.h"
14 // A class used to read text files line-by-line.
16 // LineReader reader("/path/to/file");
17 // while (reader.GetNextLine()) {
18 // const char* line = reader.line();
19 // size_t line_len = reader.length();
20 // ... line is not necessarily zero-terminated.
26 explicit LineReader(const char* path
);
29 // Open a new file for testing. Doesn't fail. If there was an error
30 // opening the file, GetNextLine() will simply return false.
31 void Open(const char* file_path
);
33 // Grab next line. Returns true on success, or false otherwise.
36 // Return the start of the current line, this is _not_ zero-terminated
37 // and always contains a final newline (\n).
38 // Only call this after a successful GetNextLine().
39 const char* line() const;
41 // Return the line length, this includes the final \n.
42 // Only call this after a successful GetNextLine().
43 size_t length() const;
53 size_t buff_capacity_
;
59 #endif // CRAZY_LINKER_LINE_READER_H