TPCCLIB
Loading...
Searching...
No Matches
csvfind.c File Reference

Find field contents in CSV struct. More...

#include "tpcclibConfig.h"
#include "tpcextensions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "tpccsv.h"

Go to the source code of this file.

Functions

int csvFindField (CSV *csv, const char *s, int start_index)
 
int csvSearchField (CSV *csv, const char *s, int start_index)
 

Detailed Description

Find field contents in CSV struct.

Definition in file csvfind.c.

Function Documentation

◆ csvFindField()

int csvFindField ( CSV * csv,
const char * s,
int start_index )

Find the CSV field with specified content. Search is case-insensitive, but otherwise match must be exact.

See also
csvSearchField, csvCell, csvRead, csvRemoveItem
Returns
field index, or <0 if not found.
Author
Vesa Oikonen
Parameters
csvPointer to CSV.
sField value to be searched for.
start_indexCSV item index [0..nr-1] from which search is started.

Definition at line 27 of file csvfind.c.

34 {
35 if(csv==NULL || s==NULL) return -2;
36 if(start_index<0 || start_index>=csv->nr) return -2;
37 for(int i=start_index; i<csv->nr; i++) if(csv->c[i].content!=NULL)
38 if(strcasecmp(csv->c[i].content, s)==0) return i;
39 return -1;
40}
char * content
Definition tpccsv.h:30
CSV_item * c
Definition tpccsv.h:38
int nr
Definition tpccsv.h:42

Referenced by parReadRES(), and tacRead4DM().

◆ csvSearchField()

int csvSearchField ( CSV * csv,
const char * s,
int start_index )

Find the CSV field which contains the given search string. Search is case-insensitive.

See also
csvFindField, csvCell, csvRead, csvRemoveItem
Returns
field index, or <0 if not found.
Author
Vesa Oikonen
Parameters
csvPointer to CSV.
sString to be searched for inside field values.
start_indexCSV field index [0..nr-1] from which search is started.

Definition at line 50 of file csvfind.c.

57 {
58 if(csv==NULL || s==NULL) return -2;
59 if(start_index<0 || start_index>=csv->nr) return -2;
60 for(int i=start_index; i<csv->nr; i++) {
61 if(csv->c[i].content==NULL || csv->c[i].content[0]=='\0') {
62 if(*s=='\0') return i; else continue;
63 }
64 if(*s=='\0') continue;
65 if(strcasestr(csv->c[i].content, s)!=NULL) return i;
66 }
67 return -1;
68}
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155

Referenced by parReadFIT(), and tacRead4DM().