util/StringCompare: use StringAPI.hxx

This commit is contained in:
Max Kellermann 2018-08-20 15:33:16 +02:00
parent 75c836fbd9
commit e85b9960f0
2 changed files with 6 additions and 5 deletions

View File

@ -32,8 +32,8 @@
bool bool
StringEndsWith(const char *haystack, const char *needle) noexcept StringEndsWith(const char *haystack, const char *needle) noexcept
{ {
const size_t haystack_length = strlen(haystack); const size_t haystack_length = StringLength(haystack);
const size_t needle_length = strlen(needle); const size_t needle_length = StringLength(needle);
return haystack_length >= needle_length && return haystack_length >= needle_length &&
memcmp(haystack + haystack_length - needle_length, memcmp(haystack + haystack_length - needle_length,
@ -43,8 +43,8 @@ StringEndsWith(const char *haystack, const char *needle) noexcept
const char * const char *
FindStringSuffix(const char *p, const char *suffix) noexcept FindStringSuffix(const char *p, const char *suffix) noexcept
{ {
const size_t p_length = strlen(p); const size_t p_length = StringLength(p);
const size_t suffix_length = strlen(suffix); const size_t suffix_length = StringLength(suffix);
if (p_length < suffix_length) if (p_length < suffix_length)
return nullptr; return nullptr;

View File

@ -31,6 +31,7 @@
#define STRING_COMPARE_HXX #define STRING_COMPARE_HXX
#include "StringView.hxx" #include "StringView.hxx"
#include "StringAPI.hxx"
#include "Compiler.h" #include "Compiler.h"
#ifdef _UNICODE #ifdef _UNICODE
@ -47,7 +48,7 @@ gcc_pure gcc_nonnull_all
static inline bool static inline bool
StringStartsWith(const char *haystack, StringView needle) noexcept StringStartsWith(const char *haystack, StringView needle) noexcept
{ {
return strncmp(haystack, needle.data, needle.size) == 0; return StringIsEqual(haystack, needle.data, needle.size);
} }
gcc_pure gcc_pure