mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
str: add case insensitive suffixcmp
This commit is contained in:
@@ -269,13 +269,26 @@ int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix)
|
||||
return prefixcmp(str, str_n, prefix, true);
|
||||
}
|
||||
|
||||
int git__suffixcmp(const char *str, const char *suffix)
|
||||
static int suffixcmp(const char *str, const char *suffix, bool icase)
|
||||
{
|
||||
size_t a = strlen(str);
|
||||
size_t b = strlen(suffix);
|
||||
|
||||
if (a < b)
|
||||
return -1;
|
||||
return strcmp(str + (a - b), suffix);
|
||||
|
||||
return icase ? strcasecmp(str + (a - b), suffix) :
|
||||
strcmp(str + (a - b), suffix);
|
||||
}
|
||||
|
||||
int git__suffixcmp(const char *str, const char *suffix)
|
||||
{
|
||||
return suffixcmp(str, suffix, false);
|
||||
}
|
||||
|
||||
int git__suffixcmp_icase(const char *str, const char *suffix)
|
||||
{
|
||||
return suffixcmp(str, suffix, true);
|
||||
}
|
||||
|
||||
char *git__strtok(char **end, const char *sep)
|
||||
|
||||
@@ -57,6 +57,7 @@ extern int git__prefixcmp_icase(const char *str, const char *prefix);
|
||||
extern int git__prefixncmp(const char *str, size_t str_n, const char *prefix);
|
||||
extern int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix);
|
||||
extern int git__suffixcmp(const char *str, const char *suffix);
|
||||
extern int git__suffixcmp_icase(const char *str, const char *suffix);
|
||||
|
||||
GIT_INLINE(int) git__signum(int val)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user