aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/wildcard.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-08-11 12:58:27 +0200
committerGitHub Enterprise <[email protected]>2025-08-11 12:58:27 +0200
commiteeac0654ab8f9e3438f2331916261a0440286fbd (patch)
tree56bd48ef8dedf91eeb25a7c26471742ab189874c /src/zenutil/wildcard.cpp
parentMerge pull request #434 from ue-foundation/zs/put-overwrite-policy (diff)
downloadzen-eeac0654ab8f9e3438f2331916261a0440286fbd.tar.xz
zen-eeac0654ab8f9e3438f2331916261a0440286fbd.zip
list build part content (#462)
- Feature: Added `zen build ls` option to list the content of a build part(s) - Build source is specified using one of the following options - `--cloud-url` cloud artifact URL to build - `--host` or `--override-host`, `--namespace`, `--bucket` and `--buildid` - `--filestorage`, `--namespace`, `--bucket` and `--buildid` - `--build-part-name` to specify a particular build part(s) in the build - `--wildcard` windows style wildcard (using * and ?) to match file paths to include - `--exclude-wildcard` windows style wildcard (using * and ?) to match file paths to exclude. Applied after --wildcard include filter - Improvement: Added `--quiet` option to zen `builds` commands to suppress non-essential output
Diffstat (limited to 'src/zenutil/wildcard.cpp')
-rw-r--r--src/zenutil/wildcard.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/zenutil/wildcard.cpp b/src/zenutil/wildcard.cpp
new file mode 100644
index 000000000..df69f6a5e
--- /dev/null
+++ b/src/zenutil/wildcard.cpp
@@ -0,0 +1,112 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include <zencore/string.h>
+#include <zenutil/wildcard.h>
+
+#if ZEN_WITH_TESTS
+# include <zencore/testing.h>
+#endif // ZEN_WITH_TESTS
+
+namespace zen {
+
+bool
+MatchWildcard(std::string_view::const_iterator WildcardIt,
+ std::string_view::const_iterator WildcardEnd,
+ std::string_view::const_iterator StringIt,
+ std::string_view::const_iterator StringEnd)
+{
+ for (; WildcardIt != WildcardEnd; WildcardIt++)
+ {
+ switch (*WildcardIt)
+ {
+ case '?':
+ if (StringIt == StringEnd)
+ {
+ return false;
+ }
+ StringIt++;
+ break;
+ case '*':
+ {
+ if ((WildcardIt + 1) == WildcardEnd)
+ {
+ return true;
+ }
+ size_t Max = std::distance(StringIt, StringEnd);
+ for (size_t i = 0; i < Max; i++)
+ {
+ if (MatchWildcard(WildcardIt + 1, WildcardEnd, StringIt + i, StringEnd))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ default:
+ if (*StringIt != *WildcardIt)
+ {
+ return false;
+ }
+ ++StringIt;
+ }
+ }
+ return StringIt == StringEnd;
+}
+
+bool
+MatchWildcard(std::string_view Wildcard, std::string_view String, bool CaseSensitive)
+{
+ if (CaseSensitive)
+ {
+ return MatchWildcard(begin(Wildcard), end(Wildcard), begin(String), end(String));
+ }
+ else
+ {
+ std::string LowercaseWildcard = ToLower(Wildcard);
+ std::string LowercaseString = ToLower(String);
+ std::string_view LowercaseWildcardView(LowercaseWildcard);
+ std::string_view LowercaseStringView(LowercaseString);
+ return MatchWildcard(begin(LowercaseWildcardView),
+ end(LowercaseWildcardView),
+ begin(LowercaseStringView),
+ end(LowercaseStringView));
+ }
+}
+
+#if ZEN_WITH_TESTS
+
+void
+wildcard_forcelink()
+{
+}
+
+TEST_CASE("Wildcard")
+{
+ CHECK(MatchWildcard("*.*", "normal.txt", true));
+ CHECK(MatchWildcard("*.*", "normal.txt", false));
+
+ CHECK(!MatchWildcard("*.*", "normal", true));
+ CHECK(!MatchWildcard("*.*", "normal", false));
+
+ CHECK(MatchWildcard("*", "hey/normal", true));
+ CHECK(MatchWildcard("*", "hey/normal", false));
+
+ CHECK(MatchWildcard("hey/*.txt", "hey/normal.txt", true));
+ CHECK(MatchWildcard("*/?ormal.txt", "hey/normal.txt", true));
+ CHECK(!MatchWildcard("*/?rmal.txt", "hey/normal.txt", true));
+ CHECK(MatchWildcard("*/?ormal.*", "hey/normal.txt", true));
+ CHECK(MatchWildcard("*/?ormal", "hey/normal", true));
+
+ CHECK(MatchWildcard("hey/*.txt", "hey/normaL.txt", false));
+ CHECK(MatchWildcard("*/?ormal.TXT", "hey/normal.txt", false));
+ CHECK(MatchWildcard("*/?ORMAL.*", "hey/normal.txt", false));
+ CHECK(MatchWildcard("*/?ormal", "HEY/normal", false));
+
+ CHECK(!MatchWildcard("hey/*.txt", "heY/normal.txt", true));
+ CHECK(!MatchWildcard("*/?ormal.TXT", "hey/normal.txt", true));
+ CHECK(!MatchWildcard("*/?ORMAL.*", "hey/normal.txt", true));
+ CHECK(!MatchWildcard("*/?ormal", "hey/normaL", true));
+}
+
+#endif
+} // namespace zen