87 const size_t start_pos,
91 const char delimiter);
99 if(isspace(part->
buffer[0]) == 0) {
109 if((
first != NULL) && (last != NULL)) {
115 if((fpart->
buffer[0] ==
'[') &&
116 ( lpart->
buffer[0] ==
']')) {
129 const size_t start_pos,
130 const size_t length) {
138 if((length == 1) && isspace(buffer[0])) {
160 if(string->
buffer[i] ==
'\\') {
174 switch(string->
buffer[i]) {
201 const char** reason) {
203 const char* msg =
"";
207 msg =
"Missing closing double quote - \"";
212 msg =
"Missing closing single quote - '";
217 msg =
"Missing closing round bracket - )";
222 msg =
"Missing open round bracket - (";
227 msg =
"Missing closing curly bracket - }";
232 msg =
"Missing opening curly bracket - {";
237 msg =
"Missing closing square bracket - ]";
242 msg =
"Missing opening square bracket - [";
254 const char delimiter) {
258 const char* part = NULL;
261 retval = (isspace(delimiter) == 0);
271 if(isspace(part[0]) != 0) {
272 if((isspace(delimiter) != 0) && (delimiter !=
'\n')) {
287 const char** reason) {
289 size_t start_pos = 0;
301 for(i = 0; i <
string->last_used; i++) {
302 if(flags.
escape ==
false) {
313 if(isspace(string->
buffer[i])) {
314 if(i - start_pos > 0) {
315 when_failed(create(
string, list, start_pos, i - start_pos), exit);
317 if(check(list, string->
buffer[i])) {
323 if(ispunct(string->
buffer[i])) {
324 if(i - start_pos > 0) {
325 when_failed(create(
string, list, start_pos, i - start_pos), exit);
327 if(check(list, string->
buffer[i])) {
336 if(i - start_pos != 0) {
337 when_failed(create(
string, list, start_pos, i - start_pos), exit);
350 bool sqbrackets =
false;
351 bool add_empty =
true;
352 bool last_is_comma =
false;
361 last_is_comma =
false;
363 switch(txt_part[0]) {
372 sqbrackets = !sqbrackets;
384 if(csv_list != NULL) {
387 sqbrackets = !sqbrackets;
401 }
else if(add_empty) {
407 last_is_comma =
true;
424 }
else if(last_is_comma && add_empty) {
438 bool sqbrackets =
false;
448 switch(txt_part[0]) {
456 sqbrackets = !sqbrackets;
463 if(ssv_list != NULL) {
466 sqbrackets = !sqbrackets;
501 const char** reason) {
524 const char** reason) {
557 const char** reason) {
564 const char** reason) {
571 const char separator) {
575 bool in_sbrackets =
false;
580 when_true(isalnum(separator) != 0, exit);
581 when_true(separator ==
'[' || separator ==
']', exit);
592 if((separator == txt_part[0]) && !in_sbrackets) {
599 if(txt_part[0] ==
'[') {
609 in_sbrackets = !in_sbrackets;
613 if((txt_part[0] ==
']') && in_sbrackets) {
616 in_sbrackets = !in_sbrackets;
620 if(isspace(txt_part[0]) && !in_sbrackets) {
628 if(current == NULL) {
642 const unsigned int index) {
657 const unsigned int index) {
658 const char* retval = NULL;
#define when_failed(x, l)
bool(* amxc_string_check_delimiter_t)(amxc_llist_t *list, const char delimiter)
static amxc_string_split_status_t amxc_build_ssv_var_list(amxc_llist_t *all, amxc_var_t *ssv_list)
static void amxc_trim_llist(amxc_llist_t *const list)
static bool amxc_string_split_update_status(const amxc_string_t *const string, size_t i, amxc_string_word_flags_t *flags)
static amxc_string_split_status_t amxc_build_csv_var_list(amxc_llist_t *all, amxc_var_t *csv_list)
int(* amxc_string_create_part_t)(const amxc_string_t *const string, amxc_llist_t *const list, const size_t start_pos, const size_t length)
static amxc_string_split_status_t amxc_string_split_words_internal(const amxc_string_t *const string, amxc_llist_t *list, amxc_string_create_part_t create, amxc_string_check_delimiter_t check, const char **reason)
static amxc_string_split_status_t amxc_string_split_word_is_valid(amxc_string_word_flags_t *flags, const char **reason)
static int amxc_string_create_part(const amxc_string_t *const string, amxc_llist_t *const list, const size_t start_pos, const size_t length)
struct _string_word_flags amxc_string_word_flags_t
static bool amxc_need_to_add_delimiter(amxc_llist_t *list, const char delimiter)
Ambiorix variant API header file.
#define cstring_t
Convenience macro.
#define amxc_container_of(addr, type, member)
Calculates the address of the containing structure.
AMXC_INLINE amxc_llist_it_t * amxc_llist_it_get_previous(const amxc_llist_it_t *const reference)
Gets the previous iterator in the list.
int amxc_llist_append(amxc_llist_t *const llist, amxc_llist_it_t *const it)
Adds an item to the end of the linked list.
int amxc_llist_init(amxc_llist_t *const llist)
Initializes a linked list.
#define amxc_llist_for_each_reverse(it, list)
Loops over the list from tail to head.
amxc_llist_it_t * amxc_llist_get_at(const amxc_llist_t *const llist, const unsigned int index)
Gets an item at a certain position of the linked list.
void amxc_llist_clean(amxc_llist_t *const llist, amxc_llist_it_delete_t func)
Removes all items from the linked list.
#define amxc_llist_for_each(it, list)
Loops over the list from head to tail.
AMXC_INLINE amxc_llist_it_t * amxc_llist_get_last(const amxc_llist_t *const llist)
Gets the last item of the linked list.
AMXC_INLINE amxc_llist_it_t * amxc_llist_get_first(const amxc_llist_t *const llist)
Gets the first item of the linked list.
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.
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.
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.
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.
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.
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.
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.
enum _amxc_string_split_status amxc_string_split_status_t
The possible string split errors.
amxc_string_split_status_t(* amxc_string_split_builder_t)(amxc_llist_t *all, amxc_var_t *var)
Callback function definition.
@ AMXC_ERROR_STRING_SPLIT_INVALID_INPUT
@ AMXC_ERROR_STRING_MISSING_CBRACKET
@ AMXC_ERROR_STRING_MISSING_RBRACKET
@ AMXC_ERROR_STRING_MISSING_SQUOTE
@ AMXC_ERROR_STRING_MISSING_DQUOTE
@ AMXC_ERROR_STRING_MISSING_SBRACKET
void amxc_string_list_it_free(amxc_llist_it_t *it)
Helper function to delete an item in a linked list.
void amxc_string_delete(amxc_string_t **string)
Frees the previously allocated string.
const char * amxc_string_get(const amxc_string_t *const string, const size_t offset)
Gets the content of the string buffer.
int amxc_string_push_buffer(amxc_string_t *const string, char *buffer, size_t length)
Sets the string buffer.
AMXC_INLINE int amxc_string_append(amxc_string_t *const string, const char *const text, const size_t length)
Appends text to the end of the current content of the string buffer.
#define amxc_string_from_llist_it(ll_it)
Get the pointer to a string structure from an amxc linked list iterator.
char * amxc_string_dup(const amxc_string_t *const string, const size_t start, size_t length)
Creates a full or partial copy of the text in the string buffer.
void amxc_string_reset(amxc_string_t *const string)
Resets the buffer, reset the content to all 0.
int amxc_string_new(amxc_string_t **string, const size_t length)
Allocates a string.
AMXC_INLINE size_t amxc_string_text_length(const amxc_string_t *const string)
Gets the current size of the used string buffer.
void amxc_string_trim(amxc_string_t *const string, amxc_string_is_char_fn_t fn)
Trim.
int amxc_string_init(amxc_string_t *const string, const size_t length)
Initializes a string.
int amxc_string_set_at(amxc_string_t *const string, const size_t pos, const char *const text, const size_t length, const amxc_string_flags_t flags)
Set text in the string buffer at a certain position.
AMXC_INLINE bool amxc_string_is_empty(const amxc_string_t *const string)
Checks if the string is empty.
void amxc_string_clean(amxc_string_t *const string)
Frees the string buffer and reset length attributes.
char * amxc_string_take_buffer(amxc_string_t *const string)
Takes the string buffer.
#define AMXC_VAR_ID_LIST
Ambiorix Linked List variant id.
#define amxc_var_add(type, var, data)
Convenience macro for adding a variant to composite variant type.
int amxc_var_set_type(amxc_var_t *const var, const uint32_t type)
Change the variant data type.
amxc_var_t * amxc_var_add_new(amxc_var_t *const var)
Adds a new variant to a composite variant.
#define amxc_var_push(type, var, val)
Pushes a value into the variant.
#define amxc_var_set(type, var, data)
Convenience macro for setting a value in a variant.
The linked list iterator structure.
struct _amxc_llist * llist
The linked list structure.
The variant struct definition.
bool between_double_quotes
bool between_single_quotes
static amxc_htable_it_t it[2000]
static amxc_llist_t * llist
static amxc_var_t * first