util/StringAPI: add StringToken(), StringIsEqualIgnoreCase(), StringCollate()

This commit is contained in:
Max Kellermann 2017-05-16 23:04:27 +02:00
parent 60bd60db03
commit 907fb257cd
1 changed files with 27 additions and 0 deletions

View File

@ -94,6 +94,12 @@ StringFindLast(char *haystack, char needle) noexcept
return strrchr(haystack, needle);
}
static inline char *
StringToken(char *str, const char *delim) noexcept
{
return strtok(str, delim);
}
gcc_nonnull_all
static inline void
UnsafeCopyString(char *dest, const char *src) noexcept
@ -134,6 +140,27 @@ StringIsEqual(const char *a, const char *b, size_t length) noexcept
return strncmp(a, b, length) == 0;
}
gcc_pure gcc_nonnull_all
static inline bool
StringIsEqualIgnoreCase(const char *a, const char *b) noexcept
{
return strcasecmp(a, b) == 0;
}
gcc_pure gcc_nonnull_all
static inline bool
StringIsEqualIgnoreCase(const char *a, const char *b, size_t size) noexcept
{
return strncasecmp(a, b, size) == 0;
}
gcc_pure gcc_nonnull_all
static inline int
StringCollate(const char *a, const char *b) noexcept
{
return strcoll(a, b);
}
/**
* Copy the string to a new allocation. The return value must be
* freed with free().