#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"
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... | |
#define CS_MAX_STR_SIZE 65535 / sizeof(char) |
|
static |
Check if a line is empty.
[in] | line | text line read from file to check |
|
static |
Count the number of lines in the file.
[in] | file_name | Name of the file to open |
|
static |
Get a token based on the difference between two strings (beginning)
[in] | str1 | Longest string which should contain the token at its beginning |
[in] | str2 | Shortest string. If null treated as 0 length string. |
|
static |
Parse a line using a given separator and returns the tokens.
[in] | line | line to parse (char *) |
[in] | separator | separator (int) |
[in,out] | n_tokens | number of tokens |
[in] | keep_missing_tokens | true or false |
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.
[in] | file_name | Name of the file to read |
[in] | separator | Separator (int) |
[in] | n_headers | Number of headers (to ignore during import) |
[in] | n_columns | Number of columns to read. -1 if all columns are to be read |
[in] | col_idx | Array of indices of columns to read (if n_columns != -1) |
[in] | ignore_missing_tokens | Ignore missing tokens (nullptr) |
[in] | n_rows | Pointer to number of rows in file |
[in] | n_cols | Pointer to number of columns in file |