[PATCH] D24101: [LLVM/Support] - Create no-arguments constructor for llvm::Regex
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 14:18:39 PDT 2016
grimar created this revision.
grimar added reviewers: rafael, dblaikie, ruiu, davide.
grimar added subscribers: llvm-commits, grimar.
This is useful when need to defer the construction,
e.g. using Regex as a member of class.
https://reviews.llvm.org/D24101
Files:
include/llvm/Support/Regex.h
lib/Support/Regex.cpp
unittests/Support/RegexTest.cpp
Index: unittests/Support/RegexTest.cpp
===================================================================
--- unittests/Support/RegexTest.cpp
+++ unittests/Support/RegexTest.cpp
@@ -100,7 +100,7 @@
EXPECT_EQ("aber", Regex("[0-9]+").sub("\\", "a1234ber", &Error));
EXPECT_EQ(Error, "replacement string contained trailing backslash");
-
+
// Backreferences
EXPECT_EQ("aa1234bber", Regex("a[0-9]+b").sub("a\\0b", "a1234ber", &Error));
EXPECT_EQ("", Error);
@@ -153,4 +153,13 @@
EXPECT_TRUE(r2.match("916"));
}
+TEST_F(RegexTest, NoArgConstructor) {
+ std::string Error;
+ Regex r1;
+ EXPECT_FALSE(r1.isValid(Error));
+ EXPECT_EQ("invalid regular expression", Error);
+ r1 = Regex("abc");
+ EXPECT_TRUE(r1.isValid(Error));
+}
+
}
Index: lib/Support/Regex.cpp
===================================================================
--- lib/Support/Regex.cpp
+++ lib/Support/Regex.cpp
@@ -19,6 +19,8 @@
#include <string>
using namespace llvm;
+Regex::Regex() : error(REG_BADPAT), preg(nullptr) {}
+
Regex::Regex(StringRef regex, unsigned Flags) {
unsigned flags = 0;
preg = new llvm_regex();
Index: include/llvm/Support/Regex.h
===================================================================
--- include/llvm/Support/Regex.h
+++ include/llvm/Support/Regex.h
@@ -43,6 +43,7 @@
BasicRegex=4
};
+ Regex();
/// Compiles the given regular expression \p Regex.
Regex(StringRef Regex, unsigned Flags = NoFlags);
Regex(const Regex &) = delete;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24101.69901.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160831/7775d3d8/attachment.bin>
More information about the llvm-commits
mailing list