STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
strlist.h File Reference
#include <stdlib.h>
#include "core.h"
#include "utils.h"
#include "str.h"
Include dependency graph for strlist.h:

Go to the source code of this file.

Data Structures

struct  StrList
 

Macros

#define STRLIST_E_SUCCESS   0
 
#define STRLIST_E_OUT_OF_RANGE   1
 
#define STRLIST_E_INVALID_VALUE   2
 
#define STRLIST_E_UNKNOWN   3
 

Typedefs

typedef int ReaderFn(size_t line, char **)
 

Functions

struct StrListstrlist_init ()
 
void strlist_remove (struct StrList *pStrList, size_t index)
 
long double strlist_item_as_long_double (struct StrList *pStrList, size_t index)
 
double strlist_item_as_double (struct StrList *pStrList, size_t index)
 
float strlist_item_as_float (struct StrList *pStrList, size_t index)
 
unsigned long long strlist_item_as_ulong_long (struct StrList *pStrList, size_t index)
 
long long strlist_item_as_long_long (struct StrList *pStrList, size_t index)
 
unsigned long strlist_item_as_ulong (struct StrList *pStrList, size_t index)
 
long strlist_item_as_long (struct StrList *pStrList, size_t index)
 
unsigned int strlist_item_as_uint (struct StrList *pStrList, size_t index)
 
int strlist_item_as_int (struct StrList *pStrList, size_t index)
 
unsigned short strlist_item_as_ushort (struct StrList *pStrList, size_t index)
 
short strlist_item_as_short (struct StrList *pStrList, size_t index)
 
unsigned char strlist_item_as_uchar (struct StrList *pStrList, size_t index)
 
char strlist_item_as_char (struct StrList *pStrList, size_t index)
 
char * strlist_item_as_str (struct StrList *pStrList, size_t index)
 
char * strlist_item (struct StrList *pStrList, size_t index)
 
void strlist_set (struct StrList **pStrList, size_t index, char *value)
 
size_t strlist_count (struct StrList *pStrList)
 
void strlist_reverse (struct StrList *pStrList)
 
void strlist_sort (struct StrList *pStrList, unsigned int mode)
 
int strlist_contains (struct StrList *pStrList, const char *value, size_t *index_of)
 
int strlist_append_file (struct StrList *pStrList, char *path, ReaderFn *readerFn)
 
void strlist_append_strlist (struct StrList *pStrList1, struct StrList *pStrList2)
 
void strlist_append (struct StrList **pStrList, char *str)
 
void strlist_append_array (struct StrList *pStrList, char **arr)
 
int strlist_append_tokenize (struct StrList *pStrList, char *str, char *delim)
 
int strlist_append_tokenize_raw (struct StrList *pStrList, char *str, char *delim)
 
int strlist_appendf (struct StrList **pStrList, const char *fmt,...)
 
struct StrListstrlist_copy (struct StrList *pStrList)
 
int strlist_cmp (struct StrList *a, struct StrList *b)
 
void strlist_free (struct StrList **pStrList)
 
const char * strlist_get_error (int flag)
 

Variables

int strlist_errno
 

Detailed Description

String array convenience functions

Function Documentation

◆ strlist_append()

void strlist_append ( struct StrList ** pStrList,
char * str )

Append a value to the list

Parameters
pStrListStrList
str

◆ strlist_append_array()

void strlist_append_array ( struct StrList * pStrList,
char ** arr )

Append the contents of an array of pointers to char

Parameters
pStrListStrList
arrNULL terminated array of strings
Here is the call graph for this function:

◆ strlist_append_file()

int strlist_append_file ( struct StrList * pStrList,
char * _path,
ReaderFn * readerFn )

Append lines from a local file or remote URL (HTTP/s only)

Parameters
pStrList
_pathfile path or HTTP/s address
readerFnpointer to a reader function (use NULL to retrieve all data)
Returns
0=success 1=no data, -1=error (spmerrno set)
Here is the call graph for this function:

◆ strlist_append_strlist()

void strlist_append_strlist ( struct StrList * pStrList1,
struct StrList * pStrList2 )

Append the contents of pStrList2 to pStrList1

Parameters
pStrList1StrList
pStrList2StrList
Here is the call graph for this function:

◆ strlist_append_tokenize()

int strlist_append_tokenize ( struct StrList * pStrList,
char * str,
char * delim )

Append the contents of a newline delimited string

Parameters
pStrListStrList
str
delim
Here is the call graph for this function:

◆ strlist_append_tokenize_raw()

int strlist_append_tokenize_raw ( struct StrList * pStrList,
char * str,
char * delim )

Append the contents of a newline delimited string without modifying the input str

Parameters
pStrListStrList
str
delim
Here is the call graph for this function:

◆ strlist_appendf()

int strlist_appendf ( struct StrList ** pStrList,
const char * fmt,
... )

Append a formatted string Behavior is identical to asprintf-family of functions

Parameters
pStrListStrList
fmtprintf format string
...format arguments
Returns
same as vasnprintf
Here is the call graph for this function:

◆ strlist_cmp()

int strlist_cmp ( struct StrList * a,
struct StrList * b )

Compare two StrLists

Parameters
aStrList structure
bStrList structure
Returns
same=0, different=1, error=-1 (a is NULL), -2 (b is NULL)
Here is the call graph for this function:

◆ strlist_contains()

int strlist_contains ( struct StrList * pStrList,
const char * value,
size_t * index_of )

Is value present in pStrList? The caller should test for success before using the value index_of

const char *needle = "world!";
struct StrList *haystack = strlist_init();
strlist_append(&haystack, "hello");
strlist_append(&haystack, "world!");
size_t index_of_item;
if (strlist_contains(haystack, needle, &index_of_item)) {
const char *item = strlist_item(haystack, index_of_item);
// index_of_item == 1
// item is "world!"
} else {
fprintf(stderr, "%s not found\n", needle);
}
void strlist_append(struct StrList **pStrList, char *str)
Definition strlist.c:38
int strlist_contains(struct StrList *pStrList, const char *value, size_t *index_of)
Definition strlist.c:166
char * strlist_item(struct StrList *pStrList, size_t index)
Definition strlist.c:484
struct StrList * strlist_init()
Definition strlist.c:829
Definition strlist.h:16
Parameters
pStrListpointer to StrList
index_of(result) index of string in pStrList, if found
valuestring to search for in pStrList
Returns
1 found
0 not found
Here is the call graph for this function:

◆ strlist_copy()

struct StrList * strlist_copy ( struct StrList * pStrList)

Produce a new copy of a StrList

Parameters
pStrListStrList
Returns
StrList copy
Here is the call graph for this function:

◆ strlist_count()

size_t strlist_count ( struct StrList * pStrList)

Get the count of values stored in a StrList

Parameters
pStrList
Returns

◆ strlist_free()

void strlist_free ( struct StrList ** pStrList)
Parameters
pStrListStrList

◆ strlist_init()

struct StrList * strlist_init ( )

Initialize an empty StrList

Returns
StrList

◆ strlist_item()

char * strlist_item ( struct StrList * pStrList,
size_t index )

Retrieve data from a StrList

Parameters
pStrList
index
Returns
string

◆ strlist_item_as_char()

char strlist_item_as_char ( struct StrList * pStrList,
size_t index )

Convert value at index to char

Parameters
pStrList
index
Returns
char
Here is the call graph for this function:

◆ strlist_item_as_double()

double strlist_item_as_double ( struct StrList * pStrList,
size_t index )

Convert value at index to double

Parameters
pStrList
index
Returns
double
Here is the call graph for this function:

◆ strlist_item_as_float()

float strlist_item_as_float ( struct StrList * pStrList,
size_t index )

Convert value at index to float

Parameters
pStrList
index
Returns
float
Here is the call graph for this function:

◆ strlist_item_as_int()

int strlist_item_as_int ( struct StrList * pStrList,
size_t index )

Convert value at index to int

Parameters
pStrList
index
Returns
int
Here is the call graph for this function:

◆ strlist_item_as_long()

long strlist_item_as_long ( struct StrList * pStrList,
size_t index )

Convert value at index to long

Parameters
pStrList
index
Returns
long
Here is the call graph for this function:

◆ strlist_item_as_long_double()

long double strlist_item_as_long_double ( struct StrList * pStrList,
size_t index )

Convert value at index to long double

Parameters
pStrList
index
Returns
long double
Here is the call graph for this function:

◆ strlist_item_as_long_long()

long long strlist_item_as_long_long ( struct StrList * pStrList,
size_t index )

Convert value at index to long long

Parameters
pStrList
index
Returns
long long
Here is the call graph for this function:

◆ strlist_item_as_short()

short strlist_item_as_short ( struct StrList * pStrList,
size_t index )

Convert value at index to short

Parameters
pStrList
index
Returns
short
Here is the call graph for this function:

◆ strlist_item_as_str()

char * strlist_item_as_str ( struct StrList * pStrList,
size_t index )

Alias of strlist_item

Parameters
pStrList
index
Returns
string
Here is the call graph for this function:

◆ strlist_item_as_uchar()

unsigned char strlist_item_as_uchar ( struct StrList * pStrList,
size_t index )

Convert value at index to unsigned char

Parameters
pStrList
index
Returns
unsigned char
Here is the call graph for this function:

◆ strlist_item_as_uint()

unsigned int strlist_item_as_uint ( struct StrList * pStrList,
size_t index )

Convert value at index to unsigned int

Parameters
pStrList
index
Returns
unsigned int
Here is the call graph for this function:

◆ strlist_item_as_ulong()

unsigned long strlist_item_as_ulong ( struct StrList * pStrList,
size_t index )

Convert value at index to unsigned long

Parameters
pStrList
index
Returns
unsigned long
Here is the call graph for this function:

◆ strlist_item_as_ulong_long()

unsigned long long strlist_item_as_ulong_long ( struct StrList * pStrList,
size_t index )

Convert value at index to unsigned long long

Parameters
pStrList
index
Returns
unsigned long long
Here is the call graph for this function:

◆ strlist_item_as_ushort()

unsigned short strlist_item_as_ushort ( struct StrList * pStrList,
size_t index )

Convert value at index to unsigned short

Parameters
pStrList
index
Returns
unsigned short
Here is the call graph for this function:

◆ strlist_remove()

void strlist_remove ( struct StrList * pStrList,
size_t index )

Remove a record by index from a StrList

Parameters
pStrList
index
Here is the call graph for this function:

◆ strlist_reverse()

void strlist_reverse ( struct StrList * pStrList)

Reverse the order of a StrList

Parameters
pStrList

◆ strlist_set()

void strlist_set ( struct StrList ** pStrList,
size_t index,
char * value )

Set value at index

Parameters
pStrList
indexpStrlist->data[index] to set
valuestring
Returns
Here is the call graph for this function:

◆ strlist_sort()

void strlist_sort ( struct StrList * pStrList,
unsigned int mode )

Sort a StrList by mode

Parameters
pStrList
modeAvailable modes: STRLIST_DEFAULT (alphabetic), STRLIST_ASC (ascending), STRLIST_DSC (descending)
Here is the call graph for this function: