# HG changeset patch # User Sascha Wilde # Date 1395664520 -3600 # Node ID 4691d9e3b1d3d2480cbc40b93d9130718fb29df1 # Parent 9104b1b2e4daf84617951063d77d3be19fbb091d# Parent ffb20e76e7d0d258b8472e6c09318062a56f4e08 Merged diff -r ffb20e76e7d0 -r 4691d9e3b1d3 common/strhelp.c --- a/common/strhelp.c Mon Mar 24 10:27:26 2014 +0000 +++ b/common/strhelp.c Mon Mar 24 13:35:20 2014 +0100 @@ -1,4 +1,4 @@ - +#include #include #include #include @@ -102,3 +102,24 @@ free (str_array); } } + +bool +str_equal (char *s1, char *s2) +{ + size_t l1 = strlen(s1); + size_t l2 = strlen(s2); + if ((l1 == l2) && + (strncmp(s1, s2, l1) == 0)) + return true; + else + return false; +} + +bool +str_starts_with (char *s1, char *s2) +{ + if (strncmp(s1, s2, strlen(s2)) == 0) + return true; + else + return false; +} diff -r ffb20e76e7d0 -r 4691d9e3b1d3 common/strhelp.h --- a/common/strhelp.h Mon Mar 24 10:27:26 2014 +0000 +++ b/common/strhelp.h Mon Mar 24 13:35:20 2014 +0100 @@ -1,6 +1,8 @@ #ifndef STRHELP_H #define STRHELP_H +#include + /** * @file strhelp.h * @brief Helper functions for c strings and memory management @@ -47,4 +49,21 @@ * @param[inout] str_array a %NULL-terminated array of strings */ void strv_free (char **str_array); + +/** + * @brief Checks whether two strings exactly match + * @param[in] s1 the first string + * @param[in] s2 the second string + * @returns true if s1 and s2 are equal + */ +bool str_equal (char *s1, char *s2); + +/** + * @brief Checks whether s2 exactly matches the beginning of s1. + * @param[in] s1 the string who's beginning is searched + * @param[in] s2 the string which is searched for + * @returns true if s1 starts with s2, false otherwise + */ +bool str_starts_with (char *s1, char *s2); + #endif