From 222dc8a239f7578cecdcb21523052140aa1192cf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 21 Oct 2013 08:42:55 +0200 Subject: Util/ASCII: add StringEqualsCaseASCII() overload with length Replaces GLib's g_ascii_strncasecmp(). --- src/util/ASCII.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util') diff --git a/src/util/ASCII.hxx b/src/util/ASCII.hxx index 0d4c8f35b..adea6dceb 100644 --- a/src/util/ASCII.hxx +++ b/src/util/ASCII.hxx @@ -51,4 +51,16 @@ StringEqualsCaseASCII(const char *a, const char *b) return strcasecmp(a, b) == 0; } +gcc_pure gcc_nonnull_all +static inline bool +StringEqualsCaseASCII(const char *a, const char *b, size_t n) +{ + assert(a != nullptr); + assert(b != nullptr); + + /* note: strcasecmp() depends on the locale, but for ASCII-only + strings, it's safe to use */ + return strncasecmp(a, b, n) == 0; +} + #endif -- cgit v1.2.3