From 25181660425aa8feb9a4d4039513396e3f78dac0 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Wed, 16 Oct 2019 22:59:02 +0000 Subject: Revert [support] GlobPattern: add support for `\` and `[!...]`, and allow `]` in more places This reverts r375051 (git commit a409afaad64ce83ea44cc30ee5f96b6e613a6e98) The patch does not work on Windows due to `\` in filenames being interpreted as escaping rather than literal path separators when used by lld linker scripts. llvm-svn: 375052 --- llvm/lib/Support/GlobPattern.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'llvm/lib/Support/GlobPattern.cpp') diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp index 8dae6941ec7..6011be86d77 100644 --- a/llvm/lib/Support/GlobPattern.cpp +++ b/llvm/lib/Support/GlobPattern.cpp @@ -19,7 +19,7 @@ using namespace llvm; static bool hasWildcard(StringRef S) { - return S.find_first_of("?*[\\") != StringRef::npos; + return S.find_first_of("?*[") != StringRef::npos; } // Expands character ranges and returns a bitmap. @@ -60,9 +60,8 @@ static Expected expand(StringRef S, StringRef Original) { } // This is a scanner for the glob pattern. -// A glob pattern token is one of "*", "?", "\", "[]", "[^]" -// (which is a negative form of "[]"), "[!]" (which is -// equivalent to "[^]"), or a non-meta character. +// A glob pattern token is one of "*", "?", "[]", "[^]" +// (which is a negative form of "[]"), or a non-meta character. // This function returns the first token in S. static Expected scan(StringRef &S, StringRef Original) { switch (S[0]) { @@ -75,16 +74,14 @@ static Expected scan(StringRef &S, StringRef Original) { S = S.substr(1); return BitVector(256, true); case '[': { - // ']' is allowed as the first character of a character class. '[]' is - // invalid. So, just skip the first character. - size_t End = S.find(']', 2); + size_t End = S.find(']', 1); if (End == StringRef::npos) return make_error("invalid glob pattern: " + Original, errc::invalid_argument); StringRef Chars = S.substr(1, End - 1); S = S.substr(End + 1); - if (Chars.startswith("^") || Chars.startswith("!")) { + if (Chars.startswith("^")) { Expected BV = expand(Chars.substr(1), Original); if (!BV) return BV.takeError(); @@ -92,11 +89,6 @@ static Expected scan(StringRef &S, StringRef Original) { } return expand(Chars, Original); } - case '\\': - // Eat this character and fall through below to treat it like a non-meta - // character. - S = S.substr(1); - LLVM_FALLTHROUGH; default: BitVector BV(256, false); BV[(uint8_t)S[0]] = true; @@ -115,9 +107,8 @@ Expected GlobPattern::create(StringRef S) { return Pat; } - // S is something like "foo*", and the "* is not escaped. We can use - // startswith(). - if (S.endswith("*") && !S.endswith("\\*") && !hasWildcard(S.drop_back())) { + // S is something like "foo*". We can use startswith(). + if (S.endswith("*") && !hasWildcard(S.drop_back())) { Pat.Prefix = S.drop_back(); return Pat; } -- cgit v1.2.3