diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx index c02cdf3af..2e7fe2624 100644 --- a/src/util/StringUtil.cxx +++ b/src/util/StringUtil.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,6 +18,7 @@ */ #include "StringUtil.hxx" +#include "StringView.hxx" #include "CharUtil.hxx" #include "ASCII.hxx" @@ -37,6 +38,20 @@ StringArrayContainsCase(const char *const*haystack, return false; } +bool +StringArrayContainsCase(const char *const*haystack, + StringView needle) noexcept +{ + assert(haystack != nullptr); + assert(needle != nullptr); + + for (; *haystack != nullptr; ++haystack) + if (needle.EqualsIgnoreCase(*haystack)) + return true; + + return false; +} + void ToUpperASCII(char *dest, const char *src, size_t size) noexcept { diff --git a/src/util/StringUtil.hxx b/src/util/StringUtil.hxx index c45e25906..1a2d44990 100644 --- a/src/util/StringUtil.hxx +++ b/src/util/StringUtil.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -24,6 +24,8 @@ #include +struct StringView; + /** * Checks whether a string array contains the specified string. * @@ -37,6 +39,11 @@ bool StringArrayContainsCase(const char *const*haystack, const char *needle) noexcept; +gcc_pure +bool +StringArrayContainsCase(const char *const*haystack, + StringView needle) noexcept; + /** * Convert the specified ASCII string (0x00..0x7f) to upper case. *