# HG changeset patch # User Sascha Wilde # Date 1395664332 -3600 # Node ID 9104b1b2e4daf84617951063d77d3be19fbb091d # Parent 65941f3d5db89c10760746d1f7b2d719d9abab03 Added string comparison functions. diff -r 65941f3d5db8 -r 9104b1b2e4da common/strhelp.c --- a/common/strhelp.c Mon Mar 24 10:06:43 2014 +0100 +++ b/common/strhelp.c Mon Mar 24 13:32:12 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 65941f3d5db8 -r 9104b1b2e4da common/strhelp.h --- a/common/strhelp.h Mon Mar 24 10:06:43 2014 +0100 +++ b/common/strhelp.h Mon Mar 24 13:32:12 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