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 cols = easycsv_print_columns(csv);
|
||||||
const unsigned int rows = easycsv_print_rows(csv);
|
const unsigned int rows = easycsv_print_rows(csv);
|
||||||
|
|
||||||
for (unsigned int row_l = 1; row_l < rows; row_l++) {
|
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 col_l = 1; col_l <= cols; col_l++) {
|
||||||
str = easycsv_read_value(csv, col_l, row_l);
|
str = easycsv_read_value(csv, col_l, row_l);
|
||||||
if (strcmp(str, value) == 0) {
|
if (strcmp(str, value) == 0) {
|
||||||
*col = col_l;
|
*col = col_l;
|
||||||
@ -127,6 +127,27 @@ easycsv_find_value(const easycsv* csv,
|
|||||||
return -1;
|
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 ***/
|
/*** Acces, read ***/
|
||||||
|
|
||||||
char*
|
char*
|
||||||
@ -162,14 +183,18 @@ easycsv_read_value(const easycsv *csv,
|
|||||||
pch = strpbrk(pch + 1, ",");
|
pch = strpbrk(pch + 1, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get span from start of string to first occurence of comma */
|
|
||||||
if (col > 1) pch++;
|
|
||||||
st = strcspn(pch, ",");
|
|
||||||
|
|
||||||
val = malloc(BUFSIZ);
|
val = malloc(BUFSIZ);
|
||||||
// If 0, no string exists!
|
if (pch == NULL) {
|
||||||
if (st > 0) {
|
st = 0;
|
||||||
strncpy(val, pch, st + 1);
|
}
|
||||||
|
else {
|
||||||
|
/* Get span from start of string to first occurence of comma */
|
||||||
|
if (col > 1) pch++;
|
||||||
|
st = strcspn(pch, ",");
|
||||||
|
// If 0, no string exists!
|
||||||
|
if (st > 0) {
|
||||||
|
strncpy(val, pch, st + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val[st] = '\0';
|
val[st] = '\0';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user