1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added str_contains_str to common

This commit is contained in:
James Booth 2015-08-26 23:52:40 +01:00
parent 55158767cc
commit ef52840d91
5 changed files with 76 additions and 0 deletions

View File

@ -192,6 +192,12 @@ str_replace(const char *string, const char *substr,
return newstr;
}
gboolean
str_contains_str(char *searchstr, char *substr)
{
return g_strrstr(searchstr, substr) != NULL;
}
int
str_contains(const char str[], int size, char ch)
{

View File

@ -104,6 +104,7 @@ gboolean create_dir(char *name);
gboolean mkdir_recursive(const char *dir);
char * str_replace(const char *string, const char *substr,
const char *replacement);
gboolean str_contains_str(char *searchstr, char *substr);
int str_contains(const char str[], int size, char ch);
gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg);
int utf8_display_len(const char * const str);

View File

@ -631,3 +631,58 @@ void strip_quotes_strips_both(void **state)
free(result);
}
void str_not_contains_str(void **state)
{
char *main = "somestring";
char *occur = "not";
assert_false(str_contains_str(main, occur));
}
void str_contains_str_at_start(void **state)
{
char *main = "somestring";
char *occur = "some";
assert_true(str_contains_str(main, occur));
}
void str_contains_str_at_end(void **state)
{
char *main = "somestring";
char *occur = "string";
assert_true(str_contains_str(main, occur));
}
void str_contains_str_in_middle(void **state)
{
char *main = "somestring";
char *occur = "str";
assert_true(str_contains_str(main, occur));
}
void str_empty_not_contains_str(void **state)
{
char *main = NULL;
char *occur = "str";
assert_false(str_contains_str(main, occur));
}
void str_not_contains_str_empty(void **state)
{
char *main = "somestring";
char *occur = NULL;
assert_false(str_contains_str(main, occur));
}
void str_empty_not_contains_str_empty(void **state)
{
char *main = NULL;
char *occur = NULL;
assert_false(str_contains_str(main, occur));
}

View File

@ -56,3 +56,10 @@ void strip_quotes_does_nothing_when_no_quoted(void **state);
void strip_quotes_strips_first(void **state);
void strip_quotes_strips_last(void **state);
void strip_quotes_strips_both(void **state);
void str_not_contains_str(void **state);
void str_contains_str_at_start(void **state);
void str_contains_str_at_end(void **state);
void str_contains_str_in_middle(void **state);
void str_empty_not_contains_str(void **state);
void str_not_contains_str_empty(void **state);
void str_empty_not_contains_str_empty(void **state);

View File

@ -95,6 +95,13 @@ int main(int argc, char* argv[]) {
unit_test(strip_quotes_strips_first),
unit_test(strip_quotes_strips_last),
unit_test(strip_quotes_strips_both),
unit_test(str_not_contains_str),
unit_test(str_contains_str_at_start),
unit_test(str_contains_str_at_end),
unit_test(str_contains_str_in_middle),
unit_test(str_empty_not_contains_str),
unit_test(str_not_contains_str_empty),
unit_test(str_empty_not_contains_str_empty),
unit_test(clear_empty),
unit_test(reset_after_create),