8.3
general documentation
cs_file_csv_parser.cpp File Reference
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include "bft_error.h"
#include "bft_mem.h"
#include "bft_printf.h"
#include "cs_base.h"
#include "cs_file.h"
#include "cs_file_csv_parser.h"
+ Include dependency graph for cs_file_csv_parser.cpp:

Macros

#define CS_MAX_STR_SIZE   65535 / sizeof(char)
 

Functions

static char * _get_token (const char *str1, const char *str2)
 Get a token based on the difference between two strings (beginning) More...
 
static char ** _parse_line (char *line, const char *separator, int *n_tokens, bool keep_missing_tokens)
 Parse a line using a given separator and returns the tokens. More...
 
static int _check_if_line_is_empty (char *line)
 Check if a line is empty. More...
 
static int _count_lines_in_file (const char *file_name)
 Count the number of lines in the file. More...
 
char *** cs_file_csv_parse (const char *file_name, const char *separator, const int n_headers, const int n_columns, const int *col_idx, const bool ignore_missing_tokens, int *n_rows, int *n_cols)
 Parse a csv file and export to a dataset (char ***). More...
 

Macro Definition Documentation

◆ CS_MAX_STR_SIZE

#define CS_MAX_STR_SIZE   65535 / sizeof(char)

Function Documentation

◆ _check_if_line_is_empty()

static int _check_if_line_is_empty ( char *  line)
static

Check if a line is empty.

Parameters
[in]linetext line read from file to check
Returns
1 if line is empty, 0 otherwise.

◆ _count_lines_in_file()

static int _count_lines_in_file ( const char *  file_name)
static

Count the number of lines in the file.

Parameters
[in]file_nameName of the file to open
Returns
number of lines

◆ _get_token()

static char * _get_token ( const char *  str1,
const char *  str2 
)
static

Get a token based on the difference between two strings (beginning)

Parameters
[in]str1Longest string which should contain the token at its beginning
[in]str2Shortest string. If null treated as 0 length string.
Returns
token

◆ _parse_line()

static char ** _parse_line ( char *  line,
const char *  separator,
int *  n_tokens,
bool  keep_missing_tokens 
)
static

Parse a line using a given separator and returns the tokens.

Parameters
[in]lineline to parse (char *)
[in]separatorseparator (int)
[in,out]n_tokensnumber of tokens
[in]keep_missing_tokenstrue or false
Returns
array of strings, each string corresponding to a token

◆ cs_file_csv_parse()

char *** cs_file_csv_parse ( const char *  file_name,
const char *  separator,
const int  n_headers,
const int  n_columns,
const int *  col_idx,
const bool  ignore_missing_tokens,
int *  n_rows,
int *  n_cols 
)

Parse a csv file and export to a dataset (char ***).

The caller is responsible for freeing the dataset when not needed anymore.

Parameters
[in]file_nameName of the file to read
[in]separatorSeparator (int)
[in]n_headersNumber of headers (to ignore during import)
[in]n_columnsNumber of columns to read. -1 if all columns are to be read
[in]col_idxArray of indices of columns to read (if n_columns != -1)
[in]ignore_missing_tokensIgnore missing tokens (nullptr)
[in]n_rowsPointer to number of rows in file
[in]n_colsPointer to number of columns in file
Returns
Pointer to newly created dataset.