# HG changeset patch # User Andre Heinecke # Date 1395673057 0 # Node ID 7a8d960d60c986f4394be90ce092d83b5e8b04d6 # Parent 4904fe01055de13c4da1d44e4dda3a0dc9240e6f# Parent 5fa4791d6d0e1c45cfb1a361b6ab44aaa0a5e1dc Merged diff -r 4904fe01055d -r 7a8d960d60c9 common/strhelp.c --- a/common/strhelp.c Mon Mar 24 14:55:48 2014 +0000 +++ b/common/strhelp.c Mon Mar 24 14:57:37 2014 +0000 @@ -1,4 +1,5 @@ - +#include +#include #include #include #include @@ -102,3 +103,38 @@ free (str_array); } } + +bool +str_equal (char *s1, char *s2) +{ + size_t l1 = strlen(s1); + size_t l2 = strlen(s2); + if ((l1 == l2) && + (strcmp(s1, s2) == 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; +} + +void +str_trim (char **s) +{ + size_t i; + if (*s != NULL) + { + while (isspace(**s)) + (*s)++; + i = strlen(*s); + while (isspace((*s)[--i])) + (*s)[i] = '\0'; + } +} diff -r 4904fe01055d -r 7a8d960d60c9 common/strhelp.h --- a/common/strhelp.h Mon Mar 24 14:55:48 2014 +0000 +++ b/common/strhelp.h Mon Mar 24 14:57:37 2014 +0000 @@ -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,30 @@ * @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); + +/** + * @brief Trims all white space from the start and end of string. + * @details the start of the string is trimmed by setting *s to the + * first non white space character. The end is trimmed by setting the + * first character after the last non white space character to \0. + * @param[inout] s ponter to the string to strip + */ +bool str_trim (char **s); + #endif