Rudiments
|
Public Member Functions | |
csvdom () | |
csvdom (bool stringcacheenabled) | |
virtual | ~csvdom () |
virtual const char * | getType () |
bool | parse (input *in) |
bool | parseFile (const char *filename) |
bool | parseString (const char *string) |
void | createRootNode () |
uint64_t | getColumnCount () |
const char * | getColumnName (uint64_t position) |
bool | getColumnPosition (const char *name, uint64_t *position) |
bool | upperCaseColumn (uint64_t position) |
bool | upperCaseColumn (const char *name) |
bool | upperCaseColumns () |
bool | lowerCaseColumn (uint64_t position) |
bool | lowerCaseColumn (const char *name) |
bool | lowerCaseColumns () |
bool | rightTrimColumn (uint64_t position) |
bool | rightTrimColumn (const char *name) |
bool | rightTrimColumns () |
bool | leftTrimColumn (uint64_t position) |
bool | leftTrimColumn (const char *name) |
bool | leftTrimColumns () |
bool | bothTrimColumn (uint64_t position) |
bool | bothTrimColumn (const char *name) |
bool | bothTrimColumns () |
bool | renameColumn (uint64_t position, const char *name, bool quoted) |
bool | renameColumn (const char *oldname, const char *newname, bool quoted) |
bool | renameColumn (const char *const *oldnames, const char *newname, bool quoted) |
bool | renameAllColumns (const char *oldname, const char *newname, bool quoted) |
bool | renameAllColumns (const char *const *oldnames, const char *newname, bool quoted) |
bool | insertColumnBefore (uint64_t position, const char *name, bool quoted) |
bool | insertColumnBefore (const char *name, const char *newname, bool quoted) |
bool | insertColumnAfter (uint64_t position, const char *name, bool quoted) |
bool | insertColumnAfter (const char *name, const char *newname, bool quoted) |
bool | moveColumn (uint64_t oldposition, uint64_t newposition) |
bool | moveColumn (const char *name, uint64_t position) |
bool | deleteColumn (uint64_t position) |
bool | deleteColumn (const char *name) |
bool | getColumnIsEmpty (uint64_t position) |
bool | getColumnIsEmpty (const char *name) |
bool | deleteEmptyColumns () |
uint64_t | getRowCount () |
domnode * | getRow (uint64_t position) |
const char * | getField (uint64_t row, uint64_t column) |
const char * | getField (uint64_t row, const char *column) |
bool | setField (uint64_t row, uint64_t column, const char *value, bool quoted) |
bool | setField (uint64_t row, const char *column, const char *value, bool quoted) |
bool | rightTrimField (uint64_t row, uint64_t column) |
bool | rightTrimField (uint64_t row, const char *column) |
bool | leftTrimField (uint64_t row, uint64_t column) |
bool | leftTrimField (uint64_t row, const char *column) |
bool | bothTrimField (uint64_t row, uint64_t column) |
bool | bothTrimField (uint64_t row, const char *column) |
void | rightTrimFields () |
void | leftTrimFields () |
void | bothTrimFields () |
bool | insertRowBefore (uint64_t position) |
bool | insertRowAfter (uint64_t position) |
bool | moveRow (uint64_t oldposition, uint64_t newposition) |
bool | deleteRow (uint64_t position) |
bool | getRowIsEmpty (uint64_t position) |
bool | deleteEmptyRows () |
void | carryValueDown (uint64_t position) |
void | carryValueDown (const char *name) |
void | carryAllValuesDown () |
Public Member Functions inherited from csvsax | |
csvsax () | |
virtual | ~csvsax () |
void | setQuote (char quote) |
char | getQuote () |
void | setDelimiter (char delimiter) |
char | getDelimiter () |
Public Member Functions inherited from sax | |
sax () | |
virtual | ~sax () |
void | setIgnoreHeaderLines (uint64_t lines) |
uint64_t | getIgnoreHeaderLines () |
void | setIgnoreFooterLines (uint64_t lines) |
uint64_t | getIgnoreFooterLines () |
const char * | getError () |
Public Member Functions inherited from object | |
virtual | ~object () |
Public Member Functions inherited from dom | |
dom () | |
dom (bool stringcacheenabled) | |
virtual | ~dom () |
virtual domnode * | getRootNode () |
virtual domnode * | getNullNode () |
virtual ssize_t | writeFile (const char *filename, mode_t perms) |
virtual ssize_t | writeFile (const char *filename, mode_t perms, bool indent) |
virtual ssize_t | write () |
virtual ssize_t | write (bool indent) |
virtual ssize_t | write (output *out) |
virtual ssize_t | write (output *out, bool indent) |
virtual ssize_t | writeXml () |
virtual ssize_t | writeXml (bool indent) |
virtual ssize_t | writeXml (output *out) |
virtual ssize_t | writeXml (output *out, bool indent) |
bool | getStringCacheEnabled () |
Public Member Functions inherited from collection | |
collection () | |
collection (collection &c) | |
collection & | operator= (collection &c) |
virtual | ~collection () |
virtual uint64_t | getCount ()=0 |
comparator * | getComparator () |
void | setComparator (comparator *newcomp) |
virtual bool | isReadOnly () |
virtual bool | isBlockBased () |
virtual uint64_t | getBlockSize () |
virtual bool | isSequentialAccess () |
virtual void | setManageValues (bool manage) |
virtual bool | getManageValues () |
virtual void | setManageArrayValues (bool manage) |
virtual bool | getManageArrayValues () |
virtual void | setManageKeys (bool manage) |
virtual bool | getManageKeys () |
virtual void | setManageArrayKeys (bool manage) |
virtual bool | getManageArrayKeys () |
virtual bool | clear ()=0 |
virtual ssize_t | writeJson ()=0 |
virtual ssize_t | writeJson (bool indent)=0 |
virtual ssize_t | writeJson (output *out)=0 |
virtual ssize_t | writeJson (output *out, bool indent)=0 |
Protected Member Functions | |
virtual bool | headerStart () |
virtual bool | column (const char *name, bool quoted) |
virtual bool | headerEnd () |
virtual bool | bodyStart () |
virtual bool | rowStart () |
virtual bool | field (const char *value, bool quoted) |
virtual bool | rowEnd () |
virtual bool | bodyEnd () |
The csvdom class implements a minimal CSV DOM parser.
It parses a file or string of CSV-formatted data and produces a dom tree representing the data. It creates an "h" element for the header, "c" element for each column, "r" element for each row, and "f" element for each field. To each "c" and "f" element, it adds a "v" attribute, containing the value, and a "q" element which can contain "y" or "n" indicating whether or not the value is quoted.
For example, the following CSV:
"col1","col2",col3,col4 field11,field12,"field13","field14" "field21",field22,field23,"field24" field31,"field32",field33,field34
would produce the following dom tree:
<h>
</h> <r> <f v="field11" q="n"> <f v="field12" q="n"> <f v="field13" q="y"> <f v="field14" q="y"> </r> <r> <f v="field21" q="y"> <f v="field22" q="n"> <f v="field23" q="n"> <f v="field24" q="y"> </r> <r> <f v="field31" q="n"> <f v="field32" q="y"> <f v="field33" q="n"> <f v="field34" q="n"> </r>
csvdom::csvdom | ( | ) |
Creates a new instance of the csvdom class.
csvdom::csvdom | ( | bool | stringcacheenabled | ) |
Creates a new instance of the csvdom class, allowing the user to enable or disable the "string cache" for this instance.
By default, as each csvdomnode is added to the csvdom tree, tag and attribute names and values are stored in a string cache and pointers into the cache are assigned to each node. Reference counters are kept and the string is removed from the cache when no more nodes are using it. If the data is highly repetitive this conserves memory at the cost of speed.
If the string cache is disabled then memory is allocated in each csvdomnode for names and values and freed when the csvdomnode is freed. This is faster but uses much more memory.
|
virtual |
Deletes this instance of the csvdom class.
|
protectedvirtual |
Gets called when the end of the body is encountered.
Reimplemented from csvsax.
|
protectedvirtual |
Gets called when the start of the body is encountered.
Reimplemented from csvsax.
bool csvdom::bothTrimColumn | ( | const char * | name | ) |
Right-trims and left-trims the name of the column "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::bothTrimColumn | ( | uint64_t | position | ) |
Right-trims and left-trims the name of the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::bothTrimColumns | ( | ) |
Right-trims and left-trims all column names.
bool csvdom::bothTrimField | ( | uint64_t | row, |
const char * | column | ||
) |
Right-trims and left-trims the value at "row","column". Returns true on success and false if no such row/column exists.
bool csvdom::bothTrimField | ( | uint64_t | row, |
uint64_t | column | ||
) |
Right-trims and left-trims the value at "row","column". Returns true on success and false if no such row/column exists.
void csvdom::bothTrimFields | ( | ) |
Right-trims and left-trims all values.
void csvdom::carryAllValuesDown | ( | ) |
For each row, for all fields, if the value for the field in that row is empty, then replace it with the value of the field at the same position from the previous row.
void csvdom::carryValueDown | ( | const char * | name | ) |
For each row, at the field in column "name", if the value for the field in that row is empty, then replace it with the value of the field at the same position from the previous row.
void csvdom::carryValueDown | ( | uint64_t | position | ) |
For each row, at the field in column "position", if the value for the field in that row is empty, then replace it with the value of the field at the same position from the previous row.
Gets called when a column name is parsed.
Reimplemented from csvsax.
|
virtual |
Creates a new root node. This is useful for building a tree from scratch.
Reimplemented from dom.
bool csvdom::deleteColumn | ( | const char * | name | ) |
Deletes the column named "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::deleteColumn | ( | uint64_t | position | ) |
Deletes the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::deleteEmptyColumns | ( | ) |
Deletes columns composed entirely of empty fields. Returns true on success and false on failure.
bool csvdom::deleteEmptyRows | ( | ) |
Deletes rows composed entirely of empty fields. Returns true on success and false on failure.
bool csvdom::deleteRow | ( | uint64_t | position | ) |
Deletes the row at "position". Returns true on success and false if "position" doesn't exist.
Gets called when a field is parsed.
Reimplemented from csvsax.
uint64_t csvdom::getColumnCount | ( | ) |
Returns the number of columns in the CSV.
bool csvdom::getColumnIsEmpty | ( | const char * | name | ) |
Returns true if the column "name" is composed entirely of empty fields.
bool csvdom::getColumnIsEmpty | ( | uint64_t | position | ) |
Returns true if the column at "position" is composed entirely of empty fields.
const char* csvdom::getColumnName | ( | uint64_t | position | ) |
Returns the column name of the column at "position". Returns NULL if "position" doesn't exist.
bool csvdom::getColumnPosition | ( | const char * | name, |
uint64_t * | position | ||
) |
Sets "position" to the position of the column named "name". Returns true on success and false if "name" doesn't exist.
const char* csvdom::getField | ( | uint64_t | row, |
const char * | column | ||
) |
Returns the value at "row","column" or NULL if no such row/column exists.
const char* csvdom::getField | ( | uint64_t | row, |
uint64_t | column | ||
) |
Returns the value at "row","column" or NULL if no such row/column exists.
domnode* csvdom::getRow | ( | uint64_t | position | ) |
Returns row at "position".
uint64_t csvdom::getRowCount | ( | ) |
Returns the number of rows in the CSV.
bool csvdom::getRowIsEmpty | ( | uint64_t | position | ) |
Returns true if the row at "position" is composed entirely of empty fields.
|
virtual |
Returns "csvdom".
Reimplemented from dom.
|
protectedvirtual |
Gets called when the end of the header is encountered.
Reimplemented from csvsax.
|
protectedvirtual |
Gets called when the start of the header is encountered.
Reimplemented from csvsax.
Inserts a column after column named "name" and names it "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. If "name" is null or empty then the column name will be set to an empty string. Returns true on success and false if "name" doesn't exist.
Inserts a column after "position" with name "name". Sets the column name to be quoted if "quoted" is true, or false otherwise. If "name" is null or empty then the column name will be set to an empty string. Returns true on success and false if "position" doesn't exist.
Inserts a column before column named "name" and names it "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. If "name" is null or empty then the column name will be set to an empty string. Returns true on success and false if "name" doesn't exist.
Inserts a column before "position" and names it "name". Sets the column name to be quoted if "quoted" is true, or false otherwise. If "name" is null or empty then the column name will be set to an empty string. Returns true on success and false if "position" doesn't exist.
bool csvdom::insertRowAfter | ( | uint64_t | position | ) |
Inserts a row after "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::insertRowBefore | ( | uint64_t | position | ) |
Inserts a row before "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::leftTrimColumn | ( | const char * | name | ) |
Left-trims the name of the column "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::leftTrimColumn | ( | uint64_t | position | ) |
Left-trims the name of the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::leftTrimColumns | ( | ) |
Left-trims all column names.
bool csvdom::leftTrimField | ( | uint64_t | row, |
const char * | column | ||
) |
Left-trims the value at "row","column". Returns true on success and false if no such row/column exists.
bool csvdom::leftTrimField | ( | uint64_t | row, |
uint64_t | column | ||
) |
Left-trims the value at "row","column". Returns true on success and false if no such row/column exists.
void csvdom::leftTrimFields | ( | ) |
Left-trims all values.
bool csvdom::lowerCaseColumn | ( | const char * | name | ) |
Lower-cases the name of the column "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::lowerCaseColumn | ( | uint64_t | position | ) |
Lower-cases the name of the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::lowerCaseColumns | ( | ) |
Lower-cases all column names.
bool csvdom::moveColumn | ( | const char * | name, |
uint64_t | position | ||
) |
Moves column named "name" to "position". Returns true on success and false if "name" doesn't exist, or if position is greater than the one more than the last position.
bool csvdom::moveColumn | ( | uint64_t | oldposition, |
uint64_t | newposition | ||
) |
Moves column at "oldposition" to "newposition". Returns true on success and false if "oldposition" doesn't exist or if "newposition" is greater than one more than the last position.
bool csvdom::moveRow | ( | uint64_t | oldposition, |
uint64_t | newposition | ||
) |
Moves row at "oldposition" to "newposition". Returns true on success and false if "oldposition" doesn't exist or if "newposition" is greater than one more than the last position.
Parses generic input "in" and generates a DOM tree.
Implements dom.
|
virtual |
Parses file "filename" and generates a DOM tree.
Implements dom.
|
virtual |
Parses string "string" and generates a DOM tree.
Implements dom.
Renames all columns named any of the names in the NULL-terminated array of names "oldname" to "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. Returns true on success and false if "oldname" doesn't exist.
Renames all columns named "oldname" to "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. Returns true on success and false if "oldname" doesn't exist.
Renames the first column named any of the names in the NULL-terminated array of names "oldname" to "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. Returns true on success and false if "oldname" doesn't exist.
Renames the first column named "oldname" to "newname". Sets the column name to be quoted if "quoted" is true, or false otherwise. Returns true on success and false if "oldname" doesn't exist.
Renames the column at "position" to "name". Sets the column name to be quoted if "quoted" is true, or false otherwise. Returns true on success and false if "position" doesn't exist.
bool csvdom::rightTrimColumn | ( | const char * | name | ) |
Right-trims the name of the column "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::rightTrimColumn | ( | uint64_t | position | ) |
Right-trims the name of the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::rightTrimColumns | ( | ) |
Right-trims all column names.
bool csvdom::rightTrimField | ( | uint64_t | row, |
const char * | column | ||
) |
Right-trims the value at "row","column". Returns true on success and false if no such row/column exists.
bool csvdom::rightTrimField | ( | uint64_t | row, |
uint64_t | column | ||
) |
Right-trims the value at "row","column". Returns true on success and false if no such row/column exists.
void csvdom::rightTrimFields | ( | ) |
Right-trims all values.
|
protectedvirtual |
Gets called when the end of a row is encountered.
Reimplemented from csvsax.
|
protectedvirtual |
Gets called when the start of a row is encountered.
Reimplemented from csvsax.
Sets the value at "row","column" to "value" and marks it "quoted". Returns true on success and false if no such row/column exists.
Sets the value at "row","column" to "value" and marks it "quoted". Returns true on success and false if no such row/column exists.
bool csvdom::upperCaseColumn | ( | const char * | name | ) |
Upper-cases the name of the column "name". Returns true on success and false if "name" doesn't exist.
bool csvdom::upperCaseColumn | ( | uint64_t | position | ) |
Upper-cases the name of the column at "position". Returns true on success and false if "position" doesn't exist.
bool csvdom::upperCaseColumns | ( | ) |
Upper-cases all column names.