Add easycsv_find_num_value (errorenous), fixed easycsv_read_value
Signed-off-by: Pradana AUMARS <paumars@courrier.dev>
This commit is contained in:
parent
cba239de98
commit
7ce936b8d1
@ -111,8 +111,8 @@ easycsv_find_value(const easycsv* csv,
|
||||
const unsigned int cols = easycsv_print_columns(csv);
|
||||
const unsigned int rows = easycsv_print_rows(csv);
|
||||
|
||||
for (unsigned int row_l = 1; row_l < rows; row_l++) {
|
||||
for (unsigned int col_l = 1; col_l < cols; col_l++) {
|
||||
for (unsigned int row_l = 1; row_l <= rows; row_l++) {
|
||||
for (unsigned int col_l = 1; col_l <= cols; col_l++) {
|
||||
str = easycsv_read_value(csv, col_l, row_l);
|
||||
if (strcmp(str, value) == 0) {
|
||||
*col = col_l;
|
||||
@ -127,6 +127,27 @@ easycsv_find_value(const easycsv* csv,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
easycsv_find_num_value(const easycsv* csv,
|
||||
const char* value)
|
||||
{
|
||||
char *str;
|
||||
int num = 0;
|
||||
const unsigned int cols = easycsv_print_columns(csv);
|
||||
const unsigned int rows = easycsv_print_rows(csv);
|
||||
|
||||
for (unsigned int row_l = 1; row_l <= rows; row_l++) {
|
||||
for (unsigned int col_l = 1; col_l <= cols; col_l++) {
|
||||
str = easycsv_read_value(csv, col_l, row_l);
|
||||
if (strcmp(str, value) == 0) {
|
||||
num++;
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/*** Acces, read ***/
|
||||
|
||||
char*
|
||||
@ -162,15 +183,19 @@ easycsv_read_value(const easycsv *csv,
|
||||
pch = strpbrk(pch + 1, ",");
|
||||
}
|
||||
|
||||
val = malloc(BUFSIZ);
|
||||
if (pch == NULL) {
|
||||
st = 0;
|
||||
}
|
||||
else {
|
||||
/* Get span from start of string to first occurence of comma */
|
||||
if (col > 1) pch++;
|
||||
st = strcspn(pch, ",");
|
||||
|
||||
val = malloc(BUFSIZ);
|
||||
// If 0, no string exists!
|
||||
if (st > 0) {
|
||||
strncpy(val, pch, st + 1);
|
||||
}
|
||||
}
|
||||
val[st] = '\0';
|
||||
|
||||
return val;
|
||||
|
Loading…
Reference in New Issue
Block a user