mirror of https://github.com/ecmwf/eccodes.git
Added new utility function string_ends_with()
This commit is contained in:
parent
a35e814154
commit
601255e7f2
|
@ -1471,6 +1471,7 @@ void rtrim(char *s);
|
||||||
const char *extract_filename(const char *filepath);
|
const char *extract_filename(const char *filepath);
|
||||||
char **string_split(char *inputString, const char *delimiter);
|
char **string_split(char *inputString, const char *delimiter);
|
||||||
int string_to_long(const char* input, long* output);
|
int string_to_long(const char* input, long* output);
|
||||||
|
int string_ends_with(const char* str1, const char* str2);
|
||||||
|
|
||||||
/* functions.c */
|
/* functions.c */
|
||||||
long grib_op_eq(long a, long b);
|
long grib_op_eq(long a, long b);
|
||||||
|
|
|
@ -116,3 +116,16 @@ int string_to_long(const char* input, long* output)
|
||||||
*output = val;
|
*output = val;
|
||||||
return GRIB_SUCCESS;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue