-
-
Save nikic/9608b350a821740402115790fd2a906f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 03940480b77c3d7ba8f5a851d74c6f4e2aefbad5 | |
Author: Nikita Popov <npopov@redhat.com> | |
Date: Tue Apr 19 15:43:59 2022 +0200 | |
Test std::regex | |
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp | |
index 6186af444e73..a56595254750 100644 | |
--- a/llvm/lib/FileCheck/FileCheck.cpp | |
+++ b/llvm/lib/FileCheck/FileCheck.cpp | |
@@ -22,6 +22,7 @@ | |
#include "llvm/Support/FormatVariadic.h" | |
#include <cstdint> | |
#include <list> | |
+#include <regex> | |
#include <set> | |
#include <tuple> | |
#include <utility> | |
@@ -1291,13 +1292,20 @@ Pattern::MatchResult Pattern::match(StringRef Buffer, | |
RegExToMatch = TmpStr; | |
} | |
- SmallVector<StringRef, 4> MatchInfo; | |
- unsigned int Flags = Regex::Newline; | |
+ std::regex_constants::syntax_option_type RegFlags = | |
+ std::regex_constants::ECMAScript; | |
+ //RegFlags |= std::regex_constants::multiline; // Requires C++17. | |
if (IgnoreCase) | |
- Flags |= Regex::IgnoreCase; | |
- if (!Regex(RegExToMatch, Flags).match(Buffer, &MatchInfo)) | |
+ RegFlags |= std::regex_constants::icase; | |
+ std::regex Reg(RegExToMatch.data(), RegExToMatch.size(), RegFlags); | |
+ std::cmatch CMatch; | |
+ if (!std::regex_search(Buffer.begin(), Buffer.end(), CMatch, Reg)) | |
return make_error<NotFoundError>(); | |
+ SmallVector<StringRef, 4> MatchInfo; | |
+ for (const auto &M : CMatch) | |
+ MatchInfo.push_back(StringRef(M.first, (size_t)M.length())); | |
+ | |
// Successful regex match. | |
assert(!MatchInfo.empty() && "Didn't get any match"); | |
StringRef FullMatch = MatchInfo[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment