IGLib 1.4
The IGLib base library for development of numerical, technical and business applications.

IG::Lib::UtilCsv Class Reference

Auxiliary utilities for dealing with files in CSV and other delimited formats. CSV - related utilities were moved here from the UtilStr class on May 2013. More...

Inheritance diagram for IG::Lib::UtilCsv:

List of all members.

Static Public Member Functions

static bool CsvIsEmptyRow (string[][] values, int rowIndex)
 Returns true if the specified line in a 2D jagged array of string cell values (arranged in rows) is empty or does not exist, otherwise false is returned.
static string CsvGetValue (string[][] values, int rowIndex, int columnIndex)
 Returns the value of the specified cell of a 2D jagged array of string cell values (arranged in rows) at the specified row and column, or null if such a value does not exist.
static int CsvColumnIndex (string[][] values, string fieldName)
 Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found. Column (or field) names are assumed to be case insensitive.
static int CsvColumnIndex (string[][] values, string fieldName, bool caseSensitive)
 Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found.
static string[][] FromCsvString (string csvString)
 Converts a CSV string to a 2D jagged array of string values and returns it. Constant UtilStr.DefaultCsvSeparator) is assumed to be a separator in the CSV format.
static string[][] FromCsvString (string csvString, string separator)
 Converts a CSV string to a 2D jagged array of string values and returns it.
static string ToCsvString (string[][] values, string separator)
 Convertsa a 2D jagged array of string values to a string in CSV format.
static string[][] LoadCsv (string filePath, string separator)
 Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file.
static string[][] LoadCsv (string filePath)
 Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file. Constant UtilStr.DefaultCsvSeparator is assumed as separator in the CSV file.
static void SaveCsv (string filePath, string[][] values, string separator, bool append)
 Saves a 2D jagged array of string cell values into a CSV file.
static void SaveCsv (string filePath, string[][] values, string separator)
 Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten.
static void SaveCsv (string filePath, string[][] values, bool append)
 Saves a 2D jagged array of string cell values into a CSV file. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.
static void SaveCsv (string filePath, string[][] values)
 Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.
static bool TestCsvStringConversion (string[][] values, string separator, bool printResults)
 Tests conversion of a 2D jagged array of string values to a CSV formatted string and back. Returns true if the array restored by conversion of the original array to a CSV string and back from a CSV string to a jagged array is the same (within inevitable ambiguities of the CSV format) as the original array.
static void ExampleCsv ()
 Example of using CSV format utilities.

Public Attributes

const string DefaultCsvSeparator = ","
 The default separator in the CSV files - comma (",").

Static Public Attributes

static string _csvSeparator = DefaultCsvSeparator

Static Protected Member Functions

static string TableToString (string[][] values, string valueSeparator)
 Returns a string that represents a table of string values. Each value is embedded in double quotes, values are separated by commas, and tables of values are separated by newlines.

Properties

static string CsvSeparator [get, set]

Detailed Description

Auxiliary utilities for dealing with files in CSV and other delimited formats.

CSV - related utilities were moved here from the UtilStr class on May 2013.

$A Igor xx May13;


Member Function Documentation

static bool IG::Lib::UtilCsv::CsvIsEmptyRow ( string  values[][],
int  rowIndex 
) [inline, static]

Returns true if the specified line in a 2D jagged array of string cell values (arranged in rows) is empty or does not exist, otherwise false is returned.

Parameters:
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
rowIndexIndex of the line that is tested for being empty or not.

$A Igor Oct08;

static string IG::Lib::UtilCsv::CsvGetValue ( string  values[][],
int  rowIndex,
int  columnIndex 
) [inline, static]

Returns the value of the specified cell of a 2D jagged array of string cell values (arranged in rows) at the specified row and column, or null if such a value does not exist.

Parameters:
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
rowIndexRow number.
columnIndexColumn number.
Returns:

$A Igor Oct08;

static int IG::Lib::UtilCsv::CsvColumnIndex ( string  values[][],
string  fieldName 
) [inline, static]

Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found. Column (or field) names are assumed to be case insensitive.

Parameters:
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
fieldNameName of the data column (field) whose column index is searched for.
Returns:
Index of data column with the specified name. Column (or field) names are assumed to be contained in the first nonempty sub-array (row).

$A Igor Oct08;

static int IG::Lib::UtilCsv::CsvColumnIndex ( string  values[][],
string  fieldName,
bool  caseSensitive 
) [inline, static]

Returns index of thr column that contains data with the specified name in a 2D jagged array of values. It is assumed that the first non-empty row (subarray) contains names of data columns. -1 is returned if the column with the specified field name is not found.

Parameters:
valuesA 2D jagged array that contains a table of tables (rows) of string cell values. Such array corresponds a table of rows of cells stored in CSV format.
fieldNameName of the data column (field) whose column index is searched for.
caseSensitiveWhether column (field) names are case sensitive or not.
Returns:
Index of data column with the specified name. Column (or field) names are assumed to be contained in the first nonempty subarray (row).

$A Igor Oct08;

static string [][] IG::Lib::UtilCsv::FromCsvString ( string  csvString) [inline, static]

Converts a CSV string to a 2D jagged array of string values and returns it. Constant UtilStr.DefaultCsvSeparator) is assumed to be a separator in the CSV format.

Parameters:
csvStringA CSV string representing data in CSV format.
Returns:
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static string [][] IG::Lib::UtilCsv::FromCsvString ( string  csvString,
string  separator 
) [inline, static]

Converts a CSV string to a 2D jagged array of string values and returns it.

Parameters:
csvStringA CSV string representing data in CSV format.
separatorSeparator that is used in CSV format (usually , or ;). If null or empty string then Constant UtilStr.DefaultCsvSeparator is taken.
Returns:
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static string IG::Lib::UtilCsv::ToCsvString ( string  values[][],
string  separator 
) [inline, static]

Convertsa a 2D jagged array of string values to a string in CSV format.

Parameters:
valuesdD table of string values that are written in CSV format.
separatorSeparator that is used to separate cell values. If null or empty string then Constant UtilStr.DefaultCsvSeparator is taken.

If the value of any cell contains separators then it is embedded in double quotes. $A Igor Oct08;

static string IG::Lib::UtilCsv::TableToString ( string  values[][],
string  valueSeparator 
) [inline, static, protected]

Returns a string that represents a table of string values. Each value is embedded in double quotes, values are separated by commas, and tables of values are separated by newlines.

Parameters:
valuesa 2D jagged array of string values that is converted to a string.
valueSeparatorSeparator that separates individual values in a row. If not specified then Constant UtilStr.DefaultCsvSeparator is taken.
Returns:
String containing values in double quotes, separated by commas and arrays of values separated by newlines, that can, for example, be printed to a console. An additional newline is added after the last array of values.

$A Igor Oct08;

static string [][] IG::Lib::UtilCsv::LoadCsv ( string  filePath,
string  separator 
) [inline, static]

Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file.

Parameters:
filePathPath to the CSV file that is read and parsed.
separatorSeparator that is used in the CSV file. If not specified (null or empty string) then Constant UtilStr.DefaultCsvSeparator is assumed.
Returns:
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static string [][] IG::Lib::UtilCsv::LoadCsv ( string  filePath) [inline, static]

Reads contents of a CSV file and returns a 2D jagged array of strigg values contained in the file. Constant UtilStr.DefaultCsvSeparator is assumed as separator in the CSV file.

Parameters:
filePathPath to the CSV file that is read and parsed.
Returns:
A 2D jagged array that contains a table of string cell values of the CSV string that is parsed. Each Subarray contains a single row of cells values.

$A Igor Oct08;

static void IG::Lib::UtilCsv::SaveCsv ( string  filePath,
string  values[][],
string  separator,
bool  append 
) [inline, static]

Saves a 2D jagged array of string cell values into a CSV file.

Parameters:
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
separatorSeparator that is used in CSV format.
appendIf true then the CSV string is appended to the existent file if the file already exists. Otherwise, existend files are overwritten.
static void IG::Lib::UtilCsv::SaveCsv ( string  filePath,
string  values[][],
string  separator 
) [inline, static]

Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten.

Parameters:
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
separatorSeparator that is used in CSV format.

$A Igor Oct08;

static void IG::Lib::UtilCsv::SaveCsv ( string  filePath,
string  values[][],
bool  append 
) [inline, static]

Saves a 2D jagged array of string cell values into a CSV file. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters:
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.
static void IG::Lib::UtilCsv::SaveCsv ( string  filePath,
string  values[][] 
) [inline, static]

Saves a 2D jagged array of string cell values into a CSV file. If the file already exists then its contents are overwritten. Constant UtilStr.DefaultCsvSeparator is assumed to be a separator for the CSV format.

Parameters:
filePathPath to the file into which contents is written.
valuesA 2D jagged array of string cell values. Each outer element contains one row of values in CSV.

$A Igor Oct08;

static bool IG::Lib::UtilCsv::TestCsvStringConversion ( string  values[][],
string  separator,
bool  printResults 
) [inline, static]

Tests conversion of a 2D jagged array of string values to a CSV formatted string and back. Returns true if the array restored by conversion of the original array to a CSV string and back from a CSV string to a jagged array is the same (within inevitable ambiguities of the CSV format) as the original array.

Parameters:
valuesOriginal 2D jagged array of values arranged by rows, which is converted to a CSV string and back.
separatorSeparator that is used in CSV format (usually this will be "," or ";", sometimes "\t"). If not specified (null or empty string) then the Constant UtilStr.DefaultCsvSeparator is assumed.
printResultsIf true then detailed results of the test are printed to a console, indicating all individual differences between the original and restored data. It is also indicated whether the individual differences are considered errors (if not then a string describing a difference begins with "WARNING").
Returns:
True if the test has passed, i.e. the restored data obtained by conversion to a CSV string and back is the same (within allowed discrepancies) than original data.
static void IG::Lib::UtilCsv::ExampleCsv ( ) [inline, static]

Example of using CSV format utilities.

$A Igor Oct08;


Member Data Documentation

The default separator in the CSV files - comma (",").


Property Documentation

string IG::Lib::UtilCsv::CsvSeparator [static, get, set]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties Events