78 {3,
',',
"a,[b,c],d"},
79 {2,
',',
"Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*,Phonebook.Contact."},
80 {4,
',',
"a , b , c , d"},
81 {8,
',',
"a,,b,,c,,d,"},
82 {4,
',',
"ab,cd,ef,gh"},
83 {3,
',',
"a,\"b,c\",d"},
84 {5,
',',
" , ab cd , ef gh , ij kl, "},
85 {5,
',',
" , ab cd , 'ef gh, ef gh' , ij kl, "},
86 {5,
',',
"[text1 , , , text2,text3]"},
87 {3,
',',
"[text1 , ,] , text2,text3"},
88 {4,
',',
"text1 , , , [text2,text3]"},
89 {3,
',',
"text1 , [ , , text2], text3"},
97 for(
int i = 0; cases[i].
text != NULL; i++) {
99 printf(
"Split string : %s\n", cases[i].text);
101 data = strdup(cases[i].text);
113 {1,
'\t',
"a b c d"},
115 {3,
'\t',
"a [b\t c] d"},
116 {2,
'\n',
"ab cd\nef\tgh"},
117 {3,
' ',
"a \"b c\" d"},
118 {3,
' ',
"[text1 text2 text3]"},
119 {3,
' ',
" [text1 text2 text3] "},
127 for(
int i = 0; cases[i].
text != NULL; i++) {
129 printf(
"Split string : %s\n", cases[i].text);
130 data = strdup(cases[i].text);
142 char* txt = strdup(
"a,[b,c],d");
158 txt = strdup(
"a[b\t c]d");
174 txt = strdup(
"a [b\t c] d");
185 txt = strdup(
"[a b\tc d text more text]");
214 assert_ptr_not_equal(string_list, NULL);
219 assert_ptr_not_equal(part, NULL);
226 assert_ptr_not_equal(part, NULL);
233 assert_ptr_not_equal(part, NULL);
238 assert_int_equal(
amxc_string_setf(&
string,
"Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*,Phonebook.Contact."), 0);
243 assert_ptr_not_equal(string_list, NULL);
245 assert_string_equal(
GETI_CHAR(&variant, 0),
"Phonebook.Contact.[FirstName=='ward'].PhoneNumber.*");
246 assert_string_equal(
GETI_CHAR(&variant, 1),
"Phonebook.Contact.");
259 const char* text =
"a,,,,,b";
268 assert_ptr_not_equal(string_list, NULL);
279 const char* text =
"','";
288 assert_ptr_not_equal(string_list, NULL);
298 assert_ptr_not_equal(string_list, NULL);
308 assert_ptr_not_equal(string_list, NULL);
326 assert_ptr_not_equal(string_list, NULL);
347 assert_ptr_not_equal(string_list, NULL);
352 assert_ptr_not_equal(part, NULL);
359 assert_ptr_not_equal(part, NULL);
365 assert_ptr_not_equal(part, NULL);
388 assert_ptr_not_equal(string_list, NULL);
393 assert_ptr_not_equal(part, NULL);
399 assert_ptr_not_equal(part, NULL);
406 assert_ptr_not_equal(part, NULL);
423 assert_int_equal(
amxc_string_append(&
string,
"[part1,[part2,part3,[part4,part5]]]", 35), 0);
427 assert_ptr_not_equal(string_list, NULL);
440 char* text =
"part1,'[part2,part3],part4',long text";
448 assert_ptr_not_equal(string_list, NULL);
453 assert_ptr_not_equal(part, NULL);
460 assert_ptr_not_equal(part, NULL);
467 assert_ptr_not_equal(part, NULL);
486 assert_int_equal(
amxc_string_append(&
string,
"part1,\"[part2,part3],part4\"", 27), 0);
490 assert_ptr_not_equal(string_list, NULL);
495 assert_ptr_not_equal(part, NULL);
502 assert_ptr_not_equal(part, NULL);
517 const char* txt =
"part1,[],part4";
526 assert_ptr_not_equal(string_list, NULL);
531 assert_ptr_not_equal(part, NULL);
538 assert_ptr_not_equal(part, NULL);
561 assert_ptr_not_equal(string_list, NULL);
566 assert_ptr_not_equal(part, NULL);
573 assert_ptr_not_equal(part, NULL);
580 assert_ptr_not_equal(part, NULL);
596 const char* text =
"a \t \tb";
605 assert_ptr_not_equal(string_list, NULL);
616 const char* text =
"' '";
625 assert_ptr_not_equal(string_list, NULL);
635 assert_ptr_not_equal(string_list, NULL);
645 assert_ptr_not_equal(string_list, NULL);
666 assert_ptr_not_equal(string_list, NULL);
671 assert_ptr_not_equal(part, NULL);
678 assert_ptr_not_equal(part, NULL);
698 assert_ptr_not_equal(string_list, NULL);
719 assert_ptr_not_equal(string_list, NULL);
724 assert_ptr_not_equal(part, NULL);
731 assert_ptr_not_equal(part, NULL);
737 assert_ptr_not_equal(part, NULL);
749 const char* text =
"\"Double quoted string \\\" with double and ' single quote\"";
750 const char* reason =
"";
761 text =
"\"Missing double quote";
764 assert_int_not_equal(strlen(reason), 0);
765 printf(
"%s\n", reason);
771 text =
"'Missing single quote";
774 assert_int_not_equal(strlen(reason), 0);
775 printf(
"%s\n", reason);
781 text =
"'single quoted string with double \" and \\' single quote'";
793 const char* text =
"{1, 2, 3}";
794 const char* reason =
"";
809 assert_int_not_equal(strlen(reason), 0);
810 printf(
"%s\n", reason);
820 assert_int_not_equal(strlen(reason), 0);
821 printf(
"%s\n", reason);
832 const char* text =
"[1, 2, 3]";
833 const char* reason =
"";
848 assert_int_not_equal(strlen(reason), 0);
849 printf(
"%s\n", reason);
859 assert_int_not_equal(strlen(reason), 0);
860 printf(
"%s\n", reason);
871 const char* text =
"(1, 2, 3)";
872 const char* reason =
"";
887 assert_int_not_equal(strlen(reason), 0);
888 printf(
"%s\n", reason);
898 assert_int_not_equal(strlen(reason), 0);
899 printf(
"%s\n", reason);
910 const char* parts[] = {
911 "This",
" ",
"is",
" ",
"a",
" ",
"text",
"\t",
"with",
" ",
"space",
" ",
"characters",
" ",
"and",
912 " ",
"\"",
"quoted text with \\\" escapes",
"\"",
" ",
"and",
" ",
",",
" ",
"some",
" ",
"(",
913 "punctuation",
")",
".",
" ",
"A",
" ",
"=",
" ",
"The",
" ",
"end",
" ", NULL
916 const char* text =
" This is a text\t\t with space characters and \"quoted text with \\\" escapes\" and , some (punctuation). A = The end ";
929 for(
int i = 0; parts[i] != NULL; i++) {
931 assert_string_equal(txt_part, parts[i]);
943 const char* text =
"!History.save \"/tmp/test.txt\"";
953 assert_ptr_not_equal(p, NULL);
957 assert_string_equal(p,
"!");
960 assert_string_equal(p,
"History");
963 assert_string_equal(p,
".");
966 assert_string_equal(p,
"save");
969 assert_string_equal(p,
" ");
972 assert_string_equal(p,
"\"");
975 assert_string_equal(p,
"/tmp/test.txt");
978 assert_string_equal(p,
"\"");
994 const char* text =
",some more text here";
1010 const char* text =
"some,more [text,here";
1043 amxc_string_setf(&
string,
"This is the first line\nThis is the second line");
1054 amxc_string_setf(&
string,
"This is the first line \n This is the second line");
#define cstring_t
Convenience macro.
#define amxc_var_from_llist_it(ll_it)
Get the variant pointer from an amxc linked list iterator.
AMXC_INLINE amxc_llist_it_t * amxc_llist_it_get_next(const amxc_llist_it_t *const reference)
Gets the next iterator in the list.
size_t amxc_llist_size(const amxc_llist_t *const llist)
Calculates the size of the linked list.
int amxc_llist_init(amxc_llist_t *const llist)
Initializes a linked list.
bool amxc_llist_is_empty(const amxc_llist_t *const llist)
Checks that the linked list is empty.
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_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_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.
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_setf(amxc_string_t *const string, const char *fmt,...) __attribute__((format(printf
Sets the content of the string using printf like formatting.
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.
void amxc_string_reset(amxc_string_t *const string)
Resets the buffer, reset the content to all 0.
int amxc_string_init(amxc_string_t *const string, const size_t length)
Initializes a string.
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_CSTRING
C-string variant id (aka char *), null terminated string.
#define AMXC_VAR_ID_LIST
Ambiorix Linked List variant id.
int amxc_var_dump(const amxc_var_t *const var, int fd)
Dumps the content of the variant in a human readable manner.
#define GETI_CHAR(a, i)
Convenience macro for getting a char* out of a composite variant by index.
uint32_t amxc_var_type_of(const amxc_var_t *const var)
Gets the variant type id of a variant.
int amxc_var_init(amxc_var_t *const var)
Initializes a variant.
void amxc_var_clean(amxc_var_t *const var)
Clean-up and reset variant.
#define amxc_var_constcast(type, var)
Takes the content from a variant.
The linked list iterator structure.
The linked list structure.
The variant struct definition.
static amxc_htable_it_t it[2000]
void test_split_word_checks_quotes(UNUSED void **state)
void test_can_split_csv_string_with_multi_array_to_variant(UNUSED void **state)
void test_split_csv_handles_sequence_of_commas_as_multiple_items(UNUSED void **state)
void test_split_ssv_string_handles_empty_string_correctly(UNUSED void **state)
void test_can_split_string_using_separator(UNUSED void **state)
void test_can_split_csv_string_to_variant(UNUSED void **state)
void test_split_string_on_new_line(UNUSED void **state)
void test_split_csv_can_handle_empty_sublist(UNUSED void **state)
void test_split_word_checks_curly_brackets(UNUSED void **state)
void test_can_split_string_using_space_separators(UNUSED void **state)
void test_functions_validates_input_arguments(UNUSED void **state)
void test_can_split_ssv_string_to_variant(UNUSED void **state)
struct _test_cases test_cases_t
void test_can_split_csv_string_supports_multi_level_array_to_variant(UNUSED void **state)
void test_split_csv_string_handles_comma_in_quotes_correctly(UNUSED void **state)
void test_can_split_csv_string_with_single_quotes_to_variant(UNUSED void **state)
void test_can_split_ssv_string_with_multi_array_to_variant(UNUSED void **state)
void test_amxc_string_split_word(UNUSED void **state)
void test_check_parts_are_correct(UNUSED void **state)
void test_can_split_csv_string_with_double_quotes_to_variant(UNUSED void **state)
void test_split_ssv_string_handles_spaces_in_quotes_correctly(UNUSED void **state)
void test_amxc_string_split_word_quotes2(UNUSED void **state)
void test_split_word_checks_round_brackets(UNUSED void **state)
void test_can_split_csv_string_can_start_with_array_to_variant(UNUSED void **state)
void test_split_csv_string_handles_empty_string_correctly(UNUSED void **state)
void test_split_word_checks_square_brackets(UNUSED void **state)
void test_amxc_string_split_word_can_start_with_punctuation(UNUSED void **state)
void test_split_ssv_handles_sequence_of_spaces_as_one_separator(UNUSED void **state)
void test_can_split_ssv_string_with_single_quotes_to_variant(UNUSED void **state)