pacemaker 3.0.3
COM automation for people with deadlines and a hatred of GUIs
 
Loading...
Searching...
No Matches
CSVLexer.hpp
Go to the documentation of this file.
1#ifndef PACEMAKER_IO_CSVLEXER_HPP_
2#define PACEMAKER_IO_CSVLEXER_HPP_
3
4#include <istream>
5#include <string>
6#include <utility>
7#include <vector>
8
9#ifndef yyFlexLexerOnce
10#include "FlexLexer.h"
11#endif
12
13namespace pacemaker::io
14{
39 class CSVLexer : public yyFlexLexer
40 {
41 public:
50 CSVLexer(std::istream *in) : yyFlexLexer(in) {}
51
53 virtual ~CSVLexer() = default;
54
57 using FlexLexer::yylex;
58
73 auto yylex(std::string *const yyval) -> int;
74
82 auto newline() -> void { this->m_content.emplace_back(std::vector<std::string>{}); }
83
91 auto append(const std::string &field) -> void { this->m_content.back().emplace_back(field); }
92
98 auto data() const & -> const std::vector<std::vector<std::string>> & { return this->m_content; }
99
105 auto data() && -> std::vector<std::vector<std::string>> { return std::move(this->m_content); }
106
114 auto reset() -> void { this->m_content.clear(); }
115
116 private:
123 std::vector<std::vector<std::string>> m_content;
124 };
125} // namespace pacemaker::io
126
127#endif // PACEMAKER_IO_CSVLEXER_HPP_
Tokenizer and record accumulator for CSV parsing.
Definition CSVLexer.hpp:40
CSVLexer(std::istream *in)
Constructs a lexer bound to the given input stream.
Definition CSVLexer.hpp:50
auto data() &&-> std::vector< std::vector< std::string > >
Moves all records accumulated so far.
Definition CSVLexer.hpp:105
auto data() const &-> const std::vector< std::vector< std::string > > &
Returns a copy of all records accumulated so far.
Definition CSVLexer.hpp:98
auto reset() -> void
Clears all accumulated records.
Definition CSVLexer.hpp:114
auto newline() -> void
Begins a new record by appending an empty row to the result.
Definition CSVLexer.hpp:82
virtual ~CSVLexer()=default
Virtual destructor; no additional cleanup beyond the base class.
auto yylex(std::string *const yyval) -> int
Scans the next token from the input stream.
auto append(const std::string &field) -> void
Appends a field value to the current (last) record.
Definition CSVLexer.hpp:91