FBB::CSV4180(3bobcat)
πΈ FBB::CSV4180 π
(it's in the 3bobcat manual bestie)
okay so. this is a class called FBB::CSV4180 and it is literally a Converter for comma separated values. no cap. pull up a chair π«Ά
β¨ NAME β¨
FBB::CSV4180 β the icon, the legend, the Converter for comma separated values. π
π¦ SYNOPSIS π¦
#include <bobcat/csv>
Linking option: -lbobcat
π DESCRIPTION π
Objects of the class CSV4180 can be used to convert series of comma separated values to the individual separated values β and bestie, we're also gonna call those fields from here on, k? The class implements RFC 4180 (cf. https://www.ietf.org/rfc/rfc4180.txt, section 2). it's giving standards-compliant, it's giving professional π
According to RFC 4180 lines contain comma separated values: comma separated values on one line are processed together, as a series of values. The final comma separated value on a line is not ended by a comma. periodt.
Comma separated values may be surrounded by double quotes. However, they must be surrounded by double quotes in these cases:
- if the values contain commas;
- if the values contain double quotes (in which case the double quote is
escapedby doubling it, e.g.,"a "" double quote"); - if the values extend over multiple lines. E.g.,
"First line
second line"
Comma separated values may be empty: the following line defines three empty comma separated values:
,,
The first empty value starts at the beginning of the line, and continues up to the first comma; the second empty value starts beyond the first comma and continues up to the second comma; the third empty value starts beyond the second comma, and continues up to the end of the line. If the line ends in blank space characters then the third value isn't empty, but contains those blank space characters. π sneaky.
By default, values are interpreted as strings. The CSV4180 class also offers facilities to ignore specific fields, or to ensure that they can be converted to integral or floating point values. The second constructor (below) expects a std::string argument defining how to interpret fields. Options are:
I: the field must be convertible to an integral value;D: the field must be convertible to a floating point value;S: the field is a string: it is used as-is;X: the field is omitted from the final set of comma separated values. I.e., if a line contains three comma separated values, and the specification"SXS"is used then this results in two comma separated values: the first and third value of three comma separated values encountered on lines.-: synonym ofX.
In addition, field specifications may contain blank spaces, which are ignored. The values must consist of standard ascii characters (e.g., UTF-8 formatted values are not recognized). π rip to my UTF-8 girlies, sorry babes.
When processing comma separated values the first line may be considered a header line. X specifications also apply to header lines, but otherwise they merely consist of S-type fields. In addition, when processing multiple input lines all non-header lines are made available in a vector of vectors of fields, whereas the header line itself can be accessed via a dedicated member (header()).
π NAMESPACE π
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
π INHERITS FROM π
-
(yeah. nothing. it's a free agent. main character energy, no parents, no drama β¨)
π CONSTRUCTORS π
explicit CSV4180(size_t nFields = 0, bool header = false, char fieldSep = β,β): The first parameter specifies the number of fields that must be present on input lines. When using the default value the number of fields encountered on the first line determines the number of fields that must be present on subsequent lines. If the second parameter istruethen the first line is interpreted as the header line. The third parameter specifies the character separating the fields. By default it's a comma, but sometimes (not part of the RFC) a semicolon is used. By specifyingfieldSepany character other than a comma can be used as field separator.explicit CSV4180(std::string const &specs, bool header = false, char fieldSep = β,β): The first parameter defines the number and types of the comma separated values on input lines. Specifications can beD: the field must be convertible to a floating point value;I: the field must be convertible to an integral value;S: the field is left as-is, and can be retrieved as astd::string.Xor-: the field is ignored and is not stored inside theCSV4180object.- blank space characters are ignored.
An exception is thrown when encountering other than the abovementioned characters are encountered. π¨
If I or D fields cannot be properly converted, or if a line contains too few or too many comma separated values the input stream's fail status is set.
The last two parameters are interpreted as the last two parameters of the previous constructor.
Copy and move constructors (and assignment operators) are available. π«Ά
π₯ OVERLOADED OPERATORS π₯
std::istream &operator>>(std::istream &in, CSV4180 &csv): One line of text is extracted frominand processed by thecsvobject. Thecsvobject may or may not already contain converted comma separated values. When empty, the first line is processed according to the specifications provided to thecsvobject at construction time. Otherwise, the comma separated values on extracted lines must match the number and types of the fields, as specified by thecsvobject. When input lines do not match these specificationsin's fail status is set. π€
π MEMBER FUNCTIONS π
void clear(size_t nFields = 0): The internally stored data (referred to by thedata,header, andlastLinemembers) are erased. By default, the required number of CSV fields is reset to0, but can be set to a specific value by specifying a value for itsnFieldsparameter.std::vector<std::vector<std::string>> const &data() const: A reference to the vector of vectors of fields stored inside theCSV4180object is returned. The vector returned bydatadoes not contain the header line. If a header line was requested it can be retrieved from theheader()member.std::vector<std::string> const &header() const: If the constructor'sheaderparameter was specified astruethen this member returns the fields encountered on the first line that was processed by theread1member. Otherwise,headerreturns a reference to an empty vector.std::string const &lastLine() const: A reference to the last line that was successfully extracted from the input stream by theread1member is returned. So once the lines containing the comma separated values have been processed, the next line on the input stream can be obtained from this member. πsize_t nValues() const: After successfully callingread1for the first time this member returns the required number of comma separated values that must be encountered on subsequent input lines.size_t read(std::istream &in, size_t nLines = 0): By default, all lines ofinare read and are processed by theread1member. By specifying a non-zero value for thenLinesparameter the specified number of lines is read fromin. Reading stops oncein's status is not good. WhennLinesis specified as zero, thenin's status flags are cleared. The number of successfully processed lines is returned.std::istream &read1(std::istream &in): One line is read frominand is parsed for its comma separated values. If parsing fails,in's fail status is set. After successfully callingread1for the first time all subsequent lines read byread1must have the same number of comma separated values as encountered when callingread1for the first time. The parsed fields are stored in a vector ofstd::stringobjects, and that vector is added to the vector of vectors of strings that is returned by thedatamember.std::vector<std::vector<std::string>> release(): The vector of vectors of fields stored inside theCSV4180object is returned. After callingreleasethe internally stored vector of fields is empty. The vector returned bydatadoes not contain the header line. If a header line was requested it can be retrieved from theheader()member. Note that this member does not reset the number of expected fields for subsequently processed CSV-lines. If that's what you want, callclearafter callingrelease. π§
β EXAMPLE β
#include <iostream>
#include <bobcat/csv4180>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
CSV4180 csv; // this processes βinputβ
size_t nLines = csv.read(cin);
cerr << nLines << " lines were read\n";
if (not csv.header().empty())
{
cerr << "header: " << β\nβ;
for (auto const &field: csv.header())
cerr << " `" << field << "β\n";
}
cerr << "# CSV values: " << csv.nValues() << β\nβ;
for (auto const &line: csv.data())
{
cerr << "Line:\n";
for (auto const &entry: line)
cerr << " `" << entry << "β\n";
}
}
π FILES π
bobcat/csv β defines the class interface
πΈ SEE ALSO πΈ
π BUGS π
None Reported.
(yes bestie, we're flawless. we ate and left no crumbs. not a single crumb. π)
π§ BOBCAT PROJECT FILES π§
- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of Brokkenβs Own Base Classes And Templates.
π COPYRIGHT π
This is free software, distributed under the terms of the GNU General Public License (GPL). slay.
β¨ AUTHOR β¨
Frank B. Brokken (f.b.brokken@rug.nl).
and that's the whole thing babes π«Ά this page came from libbobcat-dev_6.15.01, dated 2005-2026 β like, two whole decades of CSV excellence, we love a longevity moment. πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms