/usr/include/bobcat/csv4180 is in libbobcat-dev 4.08.02-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #ifndef INCLUDED_BOBCAT_CSV4180_
#define INCLUDED_BOBCAT_CSV4180_
// See RFC 4180: Common Format and MIME Type for CSV Files
#include <string>
#include <vector>
#include <iosfwd>
namespace FBB
{
class CSV4180
{
typedef std::vector<std::string> StrVector;
typedef std::vector<StrVector> DataVector;
enum State
{
START,
CRSTATE,
CHARSTATE,
DQ1,
DQ2,
};
enum CharType
{
EOS,
CR, // carriage return (\r)
CHAR,
DQUOTE,
FIELDSEP,
nCharTypes
};
int d_fieldSep;
size_t d_nRequired;
bool (CSV4180::*d_verifyTypes)() = &CSV4180::nop; // data lines
bool (CSV4180::*d_dropFields)() = &CSV4180::nop; // header fields
bool d_setHeader = false;
StrVector d_header;
State d_state;
std::string d_specs;
std::string d_str;
std::string::iterator d_begin;
std::string::iterator d_end;
std::string d_field; // the current field (complete or isn)
StrVector d_last; // the fields of the last line
DataVector d_data; // StrVectors of all processed lines
std::istream *d_in;
static bool (CSV4180::*s_fsa[][nCharTypes])();
public:
// 1: determine nFields from the
// 1st line or specify the
// # required fields
explicit CSV4180(size_t nFields = 0, bool header = false,
char fieldSep = ',');
// 2: specs specify requirements
// of fields. X-fields must be
// present but are omitted from
// d_data lines and
// d_header. Throws exception if
// unsopported specification is
// encountered.
explicit CSV4180(std::string const &specs, bool header = false,
char fieldSep = ',');
// Copy and move operations are implicitly available
std::istream &read1(std::istream &in); // in.fail(): error in input
// data
size_t read(std::istream &in, size_t nLines = 0); // read all csv
// lines or specify the
// # lines to read.
size_t nValues() const; // # CSVs (available after
// reading at least one line)
StrVector const &header() const; // the header (or empty)
std::string const &lastLine() const; // the most recently read
// line from the istream
DataVector const &data() const; // all csv lines
DataVector release(); // release all csv lines
void clear(size_t nFields = 0); // clear d_data, reset nFields
private:
void setSpecs(std::string const &specs);
bool nop();
bool dropFields();
bool verifyTypes();
bool nextLine();
CharType peek();
bool addCh(); // s_fsa functions
bool addDq1();
bool end();
bool err();
bool field();
bool req();
bool toCr();
bool toDq1();
bool toDq2();
};
inline std::istream &operator>>(std::istream &in, CSV4180 &csv)
{
return csv.read1(in);
}
inline size_t CSV4180::nValues() const
{
return d_nRequired;
}
inline CSV4180::StrVector const &CSV4180::header() const
{
return d_header;
}
inline CSV4180::DataVector const &CSV4180::data() const
{
return d_data;
}
inline CSV4180::DataVector CSV4180::release()
{
return std::move(d_data);
}
inline std::string const &CSV4180::lastLine() const
{
return d_str;
}
} // FBB
#endif
|