Added new utility function string_ends_with()

This commit is contained in:
Shahram Najm 2018-03-06 16:38:58 +00:00
parent a35e814154
commit 601255e7f2
2 changed files with 14 additions and 0 deletions

View File

@ -1471,6 +1471,7 @@ void rtrim(char *s);
const char *extract_filename(const char *filepath);
char **string_split(char *inputString, const char *delimiter);
int string_to_long(const char* input, long* output);
int string_ends_with(const char* str1, const char* str2);
/* functions.c */
long grib_op_eq(long a, long b);

View File

@ -116,3 +116,16 @@ int string_to_long(const char* input, long* output)
*output = val;
return GRIB_SUCCESS;
}
/* Return 1 if str1 ends with str2, 0 otherwise */
int string_ends_with(const char* str1, const char* str2)
{
const size_t len1 = strlen(str1);
const size_t len2 = strlen(str2);
if (len2 > len1)
return 0;
if (strcmp(&str1[len1-len2], str2) == 0)
return 1;
return 0;
}