From 1a7e3bb358bc9abf9012a727c3a45bd1da315bff Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 11 Jun 2019 19:29:40 +0200
Subject: [PATCH] util/StringUtil: add StringArrayContainsCase() overload with
 StringView

---
 src/util/StringUtil.cxx | 17 ++++++++++++++++-
 src/util/StringUtil.hxx |  9 ++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

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 <stddef.h>
 
+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.
  *