libamxc
1.10.3
C Generic Data Containers
|
Typedefs | |
typedef enum _amxc_string_split_status | amxc_string_split_status_t |
The possible string split errors. More... | |
typedef amxc_string_split_status_t(* | amxc_string_split_builder_t) (amxc_llist_t *all, amxc_var_t *var) |
Callback function definition. More... | |
Enumerations | |
enum | _amxc_string_split_status { AMXC_STRING_SPLIT_OK , AMXC_ERROR_STRING_SPLIT_INVALID_INPUT , AMXC_ERROR_STRING_MISSING_DQUOTE , AMXC_ERROR_STRING_MISSING_SQUOTE , AMXC_ERROR_STRING_MISSING_RBRACKET , AMXC_ERROR_STRING_MISSING_SBRACKET , AMXC_ERROR_STRING_MISSING_CBRACKET } |
The possible string split errors. More... | |
Functions | |
amxc_string_t * | amxc_string_get_from_llist (const amxc_llist_t *const llist, const unsigned int index) |
Helper function to be used with amxc_string_split_llist. More... | |
const char * | amxc_string_get_text_from_llist (const amxc_llist_t *const llist, const unsigned int index) |
Helper function to be used with amxc_string_split_llist. More... | |
amxc_string_split_status_t | amxc_string_split_word (const amxc_string_t *const string, amxc_llist_t *list, const char **reason) |
Split a string in individual words or punctuation signs. More... | |
amxc_string_split_status_t | amxc_string_split (const amxc_string_t *const string, amxc_var_t *var, amxc_string_split_builder_t fn, const char **reason) |
Split a string in individual words or punctuation signs. More... | |
amxc_string_split_status_t | amxc_string_csv_to_var (const amxc_string_t *const string, amxc_var_t *var, const char **reason) |
Split a string in individual parts assuming that the string contains comma separated values. More... | |
amxc_string_split_status_t | amxc_string_ssv_to_var (const amxc_string_t *const string, amxc_var_t *var, const char **reason) |
Split a string in individual parts assuming that the string contains space separated values. More... | |
amxc_string_split_status_t | amxc_string_split_to_llist (const amxc_string_t *const string, amxc_llist_t *list, const char separator) |
Simple split function using a single character separator. More... | |
Often string parsing is needed. Either parsing a string is simple, like splitting it on each occurrence of separator, or more complex, like taking into account quotes and brackets.
Using these functions may help in parsing a string.
typedef amxc_string_split_status_t(* amxc_string_split_builder_t) (amxc_llist_t *all, amxc_var_t *var) |
Callback function definition.
When using Split a string into a composite type to split a string, a filter/builder callback function can be provided.
The string is splitted into parts as describe in amxc_string_split_word, where each part is added to a linked list.
The filter/builder callback function can then combine parts or filter them out before adding them the variant which contains a linked list of variants.
all | linked list containing all string parts |
var | var the result variant. |
Definition at line 112 of file amxc_string_split.h.
typedef enum _amxc_string_split_status amxc_string_split_status_t |
The possible string split errors.
The possible string split errors.
Definition at line 82 of file amxc_string_split.h.
amxc_string_split_status_t amxc_string_csv_to_var | ( | const amxc_string_t *const | string, |
amxc_var_t * | var, | ||
const char ** | reason | ||
) |
Split a string in individual parts assuming that the string contains comma separated values.
Calls Split a string into a composite type.
This function takes into account square brackets (for lists in lists), double and single quotes. When a ',' is between double or single quotes it is considered as part of the string and not as a separator.
The provided variant will be initialized to a variant containing a linked list of variants where each item in the list is a variant containing a string.
string | The string that needs to be splitted |
var | the top level variant, will be initiated to a variant containing a linked list of variants. |
reason | when provided and parsing fails, will get filled with a human readable error string |
Definition at line 555 of file amxc_string_split.c.
amxc_string_t* amxc_string_get_from_llist | ( | const amxc_llist_t *const | llist, |
const unsigned int | index | ||
) |
Helper function to be used with amxc_string_split_llist.
It gets the reference to amxc_string_t object from an amxc_llist_t, it's not a copy.
The element is free'd when the list is deleted.
Taking a copy is the programmer's responsibility!
llist | a pointer to the linked list structure |
index | the position in the list |
Definition at line 641 of file amxc_string_split.c.
const char* amxc_string_get_text_from_llist | ( | const amxc_llist_t *const | llist, |
const unsigned int | index | ||
) |
Helper function to be used with amxc_string_split_llist.
It gets the reference to the amxc_string_t object from an amxc_llist_t, it's not a copy.
The element is free'd when the list is deleted.
Taking a copy is the programmer's responsibility!
llist | a pointer to the linked list structure |
index | the position in the list |
Definition at line 656 of file amxc_string_split.c.
amxc_string_split_status_t amxc_string_split | ( | const amxc_string_t *const | string, |
amxc_var_t * | var, | ||
amxc_string_split_builder_t | fn, | ||
const char ** | reason | ||
) |
Split a string in individual words or punctuation signs.
This functions behaves exactly the same as amxc_string_split_word, with following differences:
string | The string that needs to be splitted |
var | the top level variant, will be initiated to a variant containing a linked list of variants. |
fn | a filter/build callback function or NULL |
reason | when provided and parsing fails, will get filled with a human readable error string |
Definition at line 521 of file amxc_string_split.c.
amxc_string_split_status_t amxc_string_split_to_llist | ( | const amxc_string_t *const | string, |
amxc_llist_t * | list, | ||
const char | separator | ||
) |
Simple split function using a single character separator.
Splits a string into parts using a single character separator. A separator must be a punctuation sign except '[' or ']'. Alphanumeric characters are not allowed as a separator.
string | The string that needs to be splitted |
list | the result list |
separator | the single character separator sign |
Definition at line 569 of file amxc_string_split.c.
amxc_string_split_status_t amxc_string_split_word | ( | const amxc_string_t *const | string, |
amxc_llist_t * | list, | ||
const char ** | reason | ||
) |
Split a string in individual words or punctuation signs.
This function splits a string in individual words or punctuation signs and puts each individual part in a list. Each part in the list will be a amxc_string_t
A sequence of characters the only consists out of alfa numeric symbols [0-9a-zA-Z] is considered as one single word.
When multiple space characters are encountered after each other only one single space is added to the list.
All space characters are always converted to ' '. So when a tab or new-line character is encountered it will be added to the list as a single ' '.
Brackets and quotes are taken into account, parsing fails when there are missing quotes or brackets.
string | The string that needs to be splitted |
list | the linked list that gets filled |
reason | when provided and parsing fails, will get filled with a human readable error string |
Definition at line 499 of file amxc_string_split.c.
amxc_string_split_status_t amxc_string_ssv_to_var | ( | const amxc_string_t *const | string, |
amxc_var_t * | var, | ||
const char ** | reason | ||
) |
Split a string in individual parts assuming that the string contains space separated values.
Calls Split a string into a composite type.
This function takes into account square brackets (for lists in lists), double and single quotes. When a ' ' is between double or single quotes it is considered as part of the string and not as a separator.
The provided variant will be initialized to a variant containing a linked list of variants where each item in the list is a variant containing a string.
string | The string that needs to be splitted |
var | the top level variant, will be initiated to a variant containing a linked list of variants. |
reason | when provided and parsing fails, will get filled with a human readable error string |
Definition at line 562 of file amxc_string_split.c.