mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:07:35 +00:00
Spreadsheet/XSV: Add at() accessors
These are just aliases for operator[]. Also make the headers() getter return a vector of empty strings when the csv file has no explicit headers.
This commit is contained in:
parent
39f3f3be94
commit
3bbcde9192
2 changed files with 24 additions and 3 deletions
|
@ -49,7 +49,7 @@ ParserBehaviour operator|(ParserBehaviour left, ParserBehaviour right);
|
|||
struct ParserTraits {
|
||||
String separator;
|
||||
String quote { "\"" };
|
||||
enum {
|
||||
enum QuoteEscape {
|
||||
Repeat,
|
||||
Backslash,
|
||||
} quote_escape { Repeat };
|
||||
|
@ -103,6 +103,7 @@ public:
|
|||
|
||||
size_t size() const { return m_rows.size(); }
|
||||
Vector<String> headers() const;
|
||||
[[nodiscard]] bool has_explicit_headers() const { return (static_cast<u32>(m_behaviours) & static_cast<u32>(ParserBehaviour::ReadHeaders)) != 0; }
|
||||
|
||||
class Row {
|
||||
public:
|
||||
|
@ -115,7 +116,11 @@ public:
|
|||
StringView operator[](StringView name) const;
|
||||
StringView operator[](size_t column) const;
|
||||
|
||||
template<typename T>
|
||||
StringView at(T column) const { return this->operator[](column); }
|
||||
|
||||
size_t index() const { return m_index; }
|
||||
size_t size() const { return m_xsv.headers().size(); }
|
||||
|
||||
// FIXME: Implement begin() and end(), keeping `Field' out of the API.
|
||||
|
||||
|
@ -166,6 +171,8 @@ public:
|
|||
const Row operator[](size_t index) const;
|
||||
Row operator[](size_t index);
|
||||
|
||||
Row at(size_t index) const;
|
||||
|
||||
auto begin() { return RowIterator<false>(*this); }
|
||||
auto end() { return RowIterator<false>(*this, m_rows.size()); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue