Make lldb::Regex use StringRef.
This updates getters and setters to use StringRef instead of
const char *. I tested the build on Linux, Windows, and OSX
and saw no build or test failures. I cannot test any BSD
or Android variants, however I expect the required changes
to be minimal or non-existant.
llvm-svn: 282079
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index c34b75e..3c2e355 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -608,6 +608,8 @@
Error *error_ptr) {
bool error_set = false;
if (s && s[0]) {
+ llvm::StringRef sref = s;
+
char *end = nullptr;
lldb::addr_t addr = ::strtoull(s, &end, 0);
if (*end == '\0') {
@@ -662,10 +664,10 @@
// Since the compiler can't handle things like "main + 12" we should
// try to do this for now. The compiler doesn't like adding offsets
// to function pointer types.
- static RegularExpression g_symbol_plus_offset_regex(
- "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
+ static RegularExpression g_symbol_plus_offset_regex(llvm::StringRef(
+ "^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$"));
RegularExpression::Match regex_match(3);
- if (g_symbol_plus_offset_regex.Execute(s, ®ex_match)) {
+ if (g_symbol_plus_offset_regex.Execute(sref, ®ex_match)) {
uint64_t offset = 0;
bool add = true;
std::string name;
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 53e14c4..e540309 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -89,7 +89,8 @@
const char *command_cstr) {
m_entries.resize(m_entries.size() + 1);
// Only add the regular expression if it compiles
- if (m_entries.back().regex.Compile(re_cstr)) {
+ if (m_entries.back().regex.Compile(
+ llvm::StringRef::withNullAsEmpty(re_cstr))) {
m_entries.back().command.assign(command_cstr);
return true;
}
diff --git a/lldb/source/Interpreter/OptionValueRegex.cpp b/lldb/source/Interpreter/OptionValueRegex.cpp
index 9a19b84..86ef102 100644
--- a/lldb/source/Interpreter/OptionValueRegex.cpp
+++ b/lldb/source/Interpreter/OptionValueRegex.cpp
@@ -26,10 +26,8 @@
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
if (m_regex.IsValid()) {
- const char *regex_text = m_regex.GetText();
- if (regex_text && regex_text[0])
- strm.Printf("%s", regex_text);
- } else {
+ llvm::StringRef regex_text = m_regex.GetText();
+ strm.Printf("%s", regex_text.str().c_str());
}
}
}
@@ -53,7 +51,7 @@
case eVarSetOperationReplace:
case eVarSetOperationAssign:
- if (m_regex.Compile(value.str().c_str())) {
+ if (m_regex.Compile(value)) {
m_value_was_set = true;
NotifyValueChanged();
} else {
@@ -70,5 +68,5 @@
}
lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
- return OptionValueSP(new OptionValueRegex(m_regex.GetText()));
+ return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));
}