blob: 28a7d34f8e05dd9df359a7fac410940270d16388 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#ifndef CSV_HH
#define CSV_HH
#include "io.hh" // IWYU pragma: export
#include "line.hh"
#include <expected>
#include <memory>
#include <span>
#include <string_view>
namespace csv {
// Note that this reader is very simple, no quotes or escapes.
// Empty lines are ignored.
class Reader {
public:
virtual ~Reader() = default;
Reader(Reader const&) = delete;
Reader& operator=(Reader const&) = delete;
// Returned span is only valid until next call to read.
// Returns empty span at end-of-file and only then.
[[nodiscard]]
virtual std::expected<std::span<std::string_view>, io::ReadError> read() = 0;
// Starts at zero. Returns next line.
// So, before first read it is zero, after first read it is one.
[[nodiscard]] virtual uint64_t number() const = 0;
protected:
Reader() = default;
};
[[nodiscard]] std::unique_ptr<Reader> open(std::unique_ptr<line::Reader> reader,
char separator = ',');
[[nodiscard]] std::unique_ptr<Reader> open(std::unique_ptr<io::Reader> reader,
char separator = ',');
} // namespace csv
#endif // CSV_HH
|