Mercurial > trustbridge
changeset 132:4691d9e3b1d3
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Mon, 24 Mar 2014 13:35:20 +0100 |
parents | 9104b1b2e4da (diff) ffb20e76e7d0 (current diff) |
children | c719d3fdbc15 6232ea0c8438 |
files | |
diffstat | 2 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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; +}
--- 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 <stdbool.h> + /** * @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