73 template<
typename VAL>
77 if constexpr (std::is_floating_point_v<VAL>)
81 if constexpr (std::is_arithmetic_v<VAL>)
92 template<
typename VAL>
96 csv += (0 == csv.length()?
"":
",")
114 ,[
this](
auto const& it){ *this += it; }
141 : std::vector<CSVLine>
146 :
VecCSV(detectHeader(lines))
150 ,std::initializer_list<CSVLine> data)
152 reserve (data.size()+1);
153 appendHeaderLine(*
this, header);
154 for (
CSVLine const& line : data)
161 operator string()
const
163 std::ostringstream buffer;
164 for (
string const& line : *
this)
165 buffer << line <<
'\n';
174 return std::regex_search (line, FIND_DELIMITER_TOKEN);
181 for (
string const& s : input)
183 data.emplace_back (move(header));
190 if (input.size() > 0 and containsCSV(*input.begin()))
192 csv.reserve (input.size());
193 for (
string const& s : input)
194 csv.emplace_back (s);
197 appendHeaderLine (csv, input);
205 template<
typename TAR>
209 std::istringstream converter{encodedVal};
212 if (converter.fail())
261 explicit operator bool()
const
273 return mat[2].matched? mat[2]
283 util::RegexSearchIter::operator ++();
299 and
pos_ == size_t(
curr()->position())
321 if (
pos_ !=
size_t(
curr()->position()))
Parser to split one line of CSV data into fields.
util::RegexSearchIter const & curr() const
size_t getParsedFieldCnt()
ENABLE_USE_IN_STD_RANGE_FOR_LOOPS(CsvParser)
util::RegexSearchIter end() const
Derived specific exceptions within Lumiera's exception hierarchy.
A front-end for using printf-style formatting.
Lumiera error handling (C++ interface).
const string MATCH_QUOTED_TOKEN
const string MATCH_DELIMITER
const regex FIND_DELIMITER_TOKEN
string format4Csv(VAL const &val)
const string MATCH_SINGLE_TOKEN
void appendCsvField(string &csv, VAL const &val)
Format and append a data value to a CSV string representation.
TAR parseAs(string const &encodedVal)
parse string representation into typed value
Implementation namespace for support and library code.
string showDecimal(double val) noexcept
show maximum reproducible decimal representation
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
bool boolVal(string const &textForm)
interpret text representation of a boolean value.
Singleton-style holder for NIL or default values.
Convenience wrappers and helpers for dealing with regular expressions.
Singleton holder for NIL or default value objects.
Wrapper to simplify notation in tests.
CSVData(std::initializer_list< string > header, std::initializer_list< CSVLine > data)
CSVData(std::initializer_list< string > lines)
static VecCSV detectHeader(std::initializer_list< string > input)
static bool containsCSV(string const &line)
std::vector< CSVLine > VecCSV
static void appendHeaderLine(VecCSV &data, std::initializer_list< string > const &input)
A string with the ability to construct or append the CSV-rendering of data fields.
CSVLine & operator+=(X const &x)
wrapped regex iterator to allow usage in foreach loops
RegexSearchIter()=default
Metaprogramming with tuples-of-types and the std::tuple record.