Orcania: split string and string array functions

Orcania Potluck with different functions for different purposes that can be shared among C programs

Loading...
Searching...
No Matches
split string and string array functions

## Functions
size_t | split_string (const char *string, const char *separator, char ***return_array)
void | free_string_array (char **array)
size_t | string_array_size (char **array)
int | string_array_has_value (const char **array, const char *needle)
int | string_array_has_value_case (const char **array, const char *needle)
int | string_array_has_value_n (const char **array, const char *needle, size_t len)
int | string_array_has_value_ncase (const char **array, const char *needle, size_t len)
int | string_array_has_trimmed_value (const char **array, const char *needle)
char * | string_array_join (const char **array, const char *separator)

## Detailed Description

## Function Documentation

## ◆ free_string_array()

void free_string_array | ( | char ** | array | ) |

Clean an array of strings

Parameters

  array | an array of char * to free using o_free for each element the last element of array must be a NULL

## ◆ split_string()

size_t split_string | ( | const char * | string,
|  | const char * | separator,
|  | char *** | return_array )

Split a string into an array of strings using separator string return the number of elements to be returned, 0 on error

Parameters

  string | the string to split
  separator | the string separator, will not be included in the result
  return_array | an reference to a char ** that will be heap-allocated by the function The last element in return_array will be NULL

Returns
  the number of string elements in result_array if return_array is not NULL, set the returned array in it return_array is an array of char * ending with a NULL value return_array must be free'd after use you can use free_string_array to free return_array

## ◆ string_array_has_trimmed_value()

int string_array_has_trimmed_value | ( | const char ** | array,
|  | const char * | needle )

Check if an array of string has a specified trimmed value

Parameters

  array | an array of char * with NULL in the last element
  needle | the value to look for in array

Returns
  1 if needle exists in array, 0 otherwise

## ◆ string_array_has_value()

int string_array_has_value | ( | const char ** | array,
|  | const char * | needle )

Check if an array of string has a specified value, case sensitive

Parameters

  array | an array of char * with NULL in the last element
  needle | the value to look for in array

Returns
  1 if needle exists in array, 0 otherwise

## ◆ string_array_has_value_case()

int string_array_has_value_case | ( | const char ** | array,
|  | const char * | needle )

Check if an array of string has a specified value, case insensitive

Parameters

  array | an array of char * with NULL in the last element
  needle | the value to look for in array

Returns
  1 if needle exists in array, 0 otherwise

## ◆ string_array_has_value_n()

int string_array_has_value_n | ( | const char ** | array,
|  | const char * | needle,
|  | size_t | len )

Check if an array of string has a specified value, case sensitive, limit to len characters

Parameters

  array | an array of char * with NULL in the last element
  needle | the value to look for in array
  len | the length of needle

Returns
  1 if needle exists in array, 0 otherwise

## ◆ string_array_has_value_ncase()

int string_array_has_value_ncase | ( | const char ** | array,
|  | const char * | needle,
|  | size_t | len )

Check if an array of string has a specified value, case insensitive, limit to len characters

Parameters

  array | an array of char * with NULL in the last element
  needle | the value to look for in array
  len | the length of needle

Returns
  1 if needle exists in array, 0 otherwise

## ◆ string_array_join()

char * string_array_join | ( | const char ** | array,
|  | const char * | separator )

Join a string array into a single string

Parameters

  array | an array of char * with NULL in the last element
  separator | a string to put between the elements

Returns
  a heap allocated string

## ◆ string_array_size()

size_t string_array_size | ( | char ** | array | ) |

Count the number of elements in an array of strings

Parameters

  array | an array of char * with NULL in the last element

Returns
  the number of string elements in array