Add easycsv_get_row and easycsv_set_charp_to_value

Signed-off-by: Pradana AUMARS <paumars@courrier.dev>
This commit is contained in:
Pradana AUMARS 2021-07-17 16:46:19 +02:00
parent 959ffce49f
commit b0e3062d59
2 changed files with 46 additions and 68 deletions

View File

@ -88,46 +88,21 @@ easycsv_columns(const easycsv *csv)
return col; return col;
} }
/* char* */ char*
/* _easycsv_getrow(const _easycsv *csv, */ easycsv_get_row(const easycsv *csv,
/* const unsigned int row) */ unsigned int row)
/* { */ {
/* /\* ARGS CHECK *\/ */ char *str = malloc(BUFSIZ);
/* if (csv == NULL) { */ easycsv_rewind(csv);
/* _easycsv_printerror(csv, EASYCSV_NULLCSV); */
/* return NULL; */
/* } */
/* if (row > csv->rows) { */ for (int i = 1; i < row; i++) {
/* _easycsv_printerror(csv, EASYCSV_OVERMAXROW); */ fscanf(csv->file, "%*[^\n]\n", NULL);
/* return NULL; */ }
/* } */
/* if (row == 0) { */ fscanf(csv->file, "%s\n", str);
/* _easycsv_printerror(csv, EASYCSV_ZEROROW); */
/* return NULL; */
/* } */
/* /\* END ARGS CHECK *\/ */
/* /\* Allocate memory *\/ */ return str;
/* char *str = malloc(BUFSIZ); */ }
/* /\* Set file pointer to start *\/ */
/* rewind(csv->file); */
/* for (int i = 1; i < row; i++) */
/* { */
/* /\* skip until row is reached *\/ */
/* fscanf(csv->file, "%*[^\n]\n", NULL); */
/* } */
/* /\* Grab the row and store it in str *\/ */
/* fscanf(csv->file, "%s\n", str); */
/* // printf("row: %s\n", str); */
/* return str; */
/* } */
int int
easycsv_rewind(const easycsv *csv) easycsv_rewind(const easycsv *csv)
@ -247,24 +222,19 @@ int _easycsv_checkifvalue(struct easycsv *csv, const int col, const int row)
/* return val; */ /* return val; */
/* } */ /* } */
/* char* */ char*
/* _easycsv_setcharptovalue(const _easycsv *_priv, */ easycsv_set_charp_to_value(const char *rowstr,
/* const char *rowstr, */ unsigned int col)
/* const unsigned int col) */ {
/* { */ /* Get first occurance of comma in str, the first value is ommited but not the comma */
/* char *pch = rowstr; */ char *pch = (char*) rowstr;
/* Repeat until desired col is found */
for (unsigned int i = 1; i < col; i++) {
pch = strpbrk(pch + 1, ",");
}
/* for (unsigned int i = 1; i < col; i++) { */ return pch;
/* pch = strchr(rowstr, ','); */ }
/* if (pch == NULL) { */
/* _easycsv_printerror(_priv, EASYCSV_NULLPTR); */
/* return NULL; */
/* } */
/* pch++; */
/* } */
/* return pch; */
/* } */
/* int */ /* int */
/* _easycsv_checkcsvandstring_one(const _easycsv *csv, */ /* _easycsv_checkcsvandstring_one(const _easycsv *csv, */

View File

@ -5,15 +5,17 @@
/*** Accès ***/ /*** Accès ***/
/* /\** */ /**
/* * Returns string of a specific row, including '\n' character */ * Returns string of a specific row, including '\n' character
/* * @param[in] const pointer to _easycsv structure */ * This function does not check parameters!
/* * @param[in] row number */ * This function does not produce errors!
/* * @return string of row, NULL if error or none */ * @param[in] const pointer to easycsv structure
/* *\/ */ * @param[in] row number
/* char* */ * @return string of row (heap-allocated)
/* _easycsv_getrow(const _easycsv*, */ */
/* unsigned int); */ char*
easycsv_get_row(const easycsv*,
unsigned int);
/* /\** */ /* /\** */
/* * Returns column number of a named column *\/ */ /* * Returns column number of a named column *\/ */
@ -39,11 +41,17 @@
/* const char*, */ /* const char*, */
/* const unsigned int); */ /* const unsigned int); */
/* /\* Returns char pointer to start of value in rowstr *\/ */ /**
/* char* */ * Returns char pointer towards the n-th occurence of ',' in a given string
/* _easycsv_setcharptovalue(const _easycsv*, */ * This function does not check parameters!
/* const char*, */ * This function does not produce errors!
/* const unsigned int); */ * @param[in] string of row (string with multiple occurences of ',')
* @param[in] n-th occurence to place the char pointer
* @return char pointer towards the n-th occurence of ',' in a given string
*/
char*
easycsv_set_charp_to_value(const char*,
unsigned int);
/* /\* Insert value in row in specific column *\/ */ /* /\* Insert value in row in specific column *\/ */
/* char* */ /* char* */