Commit 1a7e3bb3 authored by Max Kellermann's avatar Max Kellermann

util/StringUtil: add StringArrayContainsCase() overload with StringView

parent 74380d2a
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "StringUtil.hxx" #include "StringUtil.hxx"
#include "StringView.hxx"
#include "CharUtil.hxx" #include "CharUtil.hxx"
#include "ASCII.hxx" #include "ASCII.hxx"
...@@ -37,6 +38,20 @@ StringArrayContainsCase(const char *const*haystack, ...@@ -37,6 +38,20 @@ StringArrayContainsCase(const char *const*haystack,
return false; 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 void
ToUpperASCII(char *dest, const char *src, size_t size) noexcept ToUpperASCII(char *dest, const char *src, size_t size) noexcept
{ {
......
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <stddef.h> #include <stddef.h>
struct StringView;
/** /**
* Checks whether a string array contains the specified string. * Checks whether a string array contains the specified string.
* *
...@@ -37,6 +39,11 @@ bool ...@@ -37,6 +39,11 @@ bool
StringArrayContainsCase(const char *const*haystack, StringArrayContainsCase(const char *const*haystack,
const char *needle) noexcept; 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. * Convert the specified ASCII string (0x00..0x7f) to upper case.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment