2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2015-06-22 21:01:46 +02:00
|
|
|
|
|
|
|
#ifndef MPD_FS_GLOB_XX
|
|
|
|
#define MPD_FS_GLOB_XX
|
|
|
|
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2015-06-22 21:01:46 +02:00
|
|
|
|
2015-06-22 18:55:49 +02:00
|
|
|
#ifdef HAVE_FNMATCH
|
|
|
|
#define HAVE_CLASS_GLOB
|
|
|
|
#include <fnmatch.h>
|
2017-12-12 10:22:20 +01:00
|
|
|
#elif defined(_WIN32)
|
2015-06-22 21:18:40 +02:00
|
|
|
#define HAVE_CLASS_GLOB
|
2015-06-22 21:01:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CLASS_GLOB
|
2021-05-19 17:36:01 +02:00
|
|
|
#include <string>
|
|
|
|
|
2015-06-22 21:01:46 +02:00
|
|
|
/**
|
|
|
|
* A pattern that matches file names. It may contain shell wildcards
|
|
|
|
* (asterisk and question mark).
|
|
|
|
*/
|
|
|
|
class Glob {
|
2015-06-22 18:55:49 +02:00
|
|
|
std::string pattern;
|
2015-06-22 21:01:46 +02:00
|
|
|
|
|
|
|
public:
|
2015-06-22 18:55:49 +02:00
|
|
|
explicit Glob(const char *_pattern)
|
|
|
|
:pattern(_pattern) {}
|
|
|
|
|
2021-05-19 17:36:40 +02:00
|
|
|
Glob(Glob &&other) noexcept = default;
|
|
|
|
Glob &operator=(Glob &&other) noexcept = default;
|
2015-06-22 21:01:46 +02:00
|
|
|
|
2021-10-13 11:28:04 +02:00
|
|
|
[[gnu::pure]]
|
2021-05-19 17:39:03 +02:00
|
|
|
bool Check(const char *name_fs) const noexcept;
|
2015-06-22 21:01:46 +02:00
|
|
|
};
|
|
|
|
|
2021-05-19 17:39:03 +02:00
|
|
|
#ifdef HAVE_FNMATCH
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
Glob::Check(const char *name_fs) const noexcept
|
|
|
|
{
|
|
|
|
return fnmatch(pattern.c_str(), name_fs, 0) == 0;
|
|
|
|
}
|
|
|
|
|
2015-06-22 21:01:46 +02:00
|
|
|
#endif
|
|
|
|
|
2021-05-19 17:39:03 +02:00
|
|
|
#endif /* HAVE_CLASS_GLOB */
|
|
|
|
|
2015-06-22 21:01:46 +02:00
|
|
|
#endif
|