util: Add virStringHasSuffix()

This is the case-sensitive counterpart of the existing
virStringHasCaseSuffix() function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Andrea Bolognani 2019-03-06 17:05:03 +01:00
parent b5cc0a7f29
commit d93b9e8829
3 changed files with 16 additions and 0 deletions

View File

@ -2966,6 +2966,7 @@ virStringFilterChars;
virStringHasCaseSuffix;
virStringHasChars;
virStringHasControlChars;
virStringHasSuffix;
virStringIsEmpty;
virStringIsPrintable;
virStringListAdd;

View File

@ -1235,6 +1235,19 @@ virStringReplace(const char *haystack,
return virBufferContentAndReset(&buf);
}
bool
virStringHasSuffix(const char *str,
const char *suffix)
{
int len = strlen(str);
int suffixlen = strlen(suffix);
if (len < suffixlen)
return false;
return STREQ(str + len - suffixlen, suffix);
}
int
virStringHasCaseSuffix(const char *str,
const char *suffix)

View File

@ -288,6 +288,8 @@ char *virStringReplace(const char *haystack,
const char *newneedle)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
bool virStringHasSuffix(const char *str,
const char *suffix);
int virStringHasCaseSuffix(const char *str,
const char *suffix);
int virStringStripSuffix(char *str,