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/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index 9d70f40..5eebc78 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -511,7 +511,7 @@
     pos = regex_str.insert(pos, '\\');
     pos = find_if(pos + 2, regex_str.end(), regex_chars);
   }
-  m_regex.Compile(regex_str.c_str());
+  m_regex.Compile(regex_str);
 }
 
 Searcher::Depth CommandCompletions::SymbolCompleter::GetDepth() {
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index b0c8332..72e7e12 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -529,7 +529,7 @@
     case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
                                  // name
       {
-        RegularExpression regexp(m_options.m_func_regexp.c_str());
+        RegularExpression regexp(m_options.m_func_regexp);
         if (!regexp.IsValid()) {
           char err_str[1024];
           regexp.GetErrorAsCString(err_str, sizeof(err_str));
@@ -564,7 +564,7 @@
         }
       }
 
-      RegularExpression regexp(m_options.m_source_text_regexp.c_str());
+      RegularExpression regexp(m_options.m_source_text_regexp);
       if (!regexp.IsValid()) {
         char err_str[1024];
         regexp.GetErrorAsCString(err_str, sizeof(err_str));
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 05b16bc..0c28bd0 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -547,8 +547,9 @@
              ++idx) {
           if (m_option_variable.use_regex) {
             const size_t regex_start_index = regex_var_list.GetSize();
-            RegularExpression regex(name_cstr);
-            if (regex.Compile(name_cstr)) {
+            llvm::StringRef name_str(name_cstr);
+            RegularExpression regex(name_str);
+            if (regex.Compile(name_str)) {
               size_t num_matches = 0;
               const size_t num_new_regex_vars =
                   variable_list->AppendVariablesIfUnique(regex, regex_var_list,
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index d7e4dfa..321341c 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -807,7 +807,7 @@
         size_t matches = 0;
         bool use_var_name = false;
         if (m_option_variable.use_regex) {
-          RegularExpression regex(arg);
+          RegularExpression regex(llvm::StringRef::withNullAsEmpty(arg));
           if (!regex.IsValid()) {
             result.GetErrorStream().Printf(
                 "error: invalid regular expression: '%s'\n", arg);
@@ -941,7 +941,8 @@
               } else if (sc.module_sp) {
                 // Get all global variables for this module
                 lldb_private::RegularExpression all_globals_regex(
-                    "."); // Any global with at least one character
+                    llvm::StringRef(
+                        ".")); // Any global with at least one character
                 VariableList variable_list;
                 sc.module_sp->FindGlobalVariables(all_globals_regex, append,
                                                   UINT32_MAX, variable_list);
@@ -1517,7 +1518,7 @@
         ConstString symbol_name(name);
         uint32_t num_matches = 0;
         if (name_is_regex) {
-          RegularExpression name_regexp(name);
+          RegularExpression name_regexp(symbol_name.GetStringRef());
           num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
               name_regexp, eSymbolTypeAny, match_indexes);
         } else {
@@ -1579,7 +1580,7 @@
     const bool append = true;
     size_t num_matches = 0;
     if (name_is_regex) {
-      RegularExpression function_name_regex(name);
+      RegularExpression function_name_regex((llvm::StringRef(name)));
       num_matches = module->FindFunctions(function_name_regex, include_symbols,
                                           include_inlines, append, sc_list);
     } else {
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 358e9c6..0fbebb9 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -697,7 +697,7 @@
       if (typeCS) {
         if (m_command_options.m_regex) {
           RegularExpressionSP typeRX(new RegularExpression());
-          if (!typeRX->Compile(typeCS.GetCString())) {
+          if (!typeRX->Compile(typeCS.GetStringRef())) {
             result.AppendError(
                 "regex format error (maybe this is not really a regex?)");
             result.SetStatus(eReturnStatusFailed);
@@ -1102,10 +1102,10 @@
     if (m_options.m_category_regex.OptionWasSet()) {
       category_regex.reset(new RegularExpression());
       if (!category_regex->Compile(
-              m_options.m_category_regex.GetCurrentValue())) {
+              m_options.m_category_regex.GetCurrentValueAsRef())) {
         result.AppendErrorWithFormat(
             "syntax error in category regular expression '%s'",
-            m_options.m_category_regex.GetCurrentValue());
+            m_options.m_category_regex.GetCurrentValueAsRef().str().c_str());
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
@@ -1114,7 +1114,7 @@
     if (argc == 1) {
       const char *arg = command.GetArgumentAtIndex(0);
       formatter_regex.reset(new RegularExpression());
-      if (!formatter_regex->Compile(arg)) {
+      if (!formatter_regex->Compile(llvm::StringRef::withNullAsEmpty(arg))) {
         result.AppendErrorWithFormat("syntax error in regular expression '%s'",
                                      arg);
         result.SetStatus(eReturnStatusFailed);
@@ -1137,9 +1137,9 @@
                       const FormatterSharedPointer &format_sp) -> bool {
           if (formatter_regex) {
             bool escape = true;
-            if (0 == strcmp(name.AsCString(), formatter_regex->GetText())) {
+            if (name.GetStringRef() == formatter_regex->GetText()) {
               escape = false;
-            } else if (formatter_regex->Execute(name.AsCString())) {
+            } else if (formatter_regex->Execute(name.GetStringRef())) {
               escape = false;
             }
 
@@ -1159,7 +1159,7 @@
                           const FormatterSharedPointer &format_sp) -> bool {
           if (formatter_regex) {
             bool escape = true;
-            if (0 == strcmp(regex_sp->GetText(), formatter_regex->GetText())) {
+            if (regex_sp->GetText() == formatter_regex->GetText()) {
               escape = false;
             } else if (formatter_regex->Execute(regex_sp->GetText())) {
               escape = false;
@@ -1170,7 +1170,8 @@
           }
 
           any_printed = true;
-          result.GetOutputStream().Printf("%s: %s\n", regex_sp->GetText(),
+          result.GetOutputStream().Printf("%s: %s\n",
+                                          regex_sp->GetText().str().c_str(),
                                           format_sp->GetDescription().c_str());
           return true;
         });
@@ -1191,9 +1192,11 @@
               const lldb::TypeCategoryImplSP &category) -> bool {
             if (category_regex) {
               bool escape = true;
-              if (0 == strcmp(category->GetName(), category_regex->GetText())) {
+              if (category->GetName() == category_regex->GetText()) {
                 escape = false;
-              } else if (category_regex->Execute(category->GetName())) {
+              } else if (category_regex->Execute(
+                             llvm::StringRef::withNullAsEmpty(
+                                 category->GetName()))) {
                 escape = false;
               }
 
@@ -1693,7 +1696,7 @@
 
   if (type == eRegexSummary) {
     RegularExpressionSP typeRX(new RegularExpression());
-    if (!typeRX->Compile(type_name.GetCString())) {
+    if (!typeRX->Compile(type_name.GetStringRef())) {
       if (error)
         error->SetErrorString(
             "regex format error (maybe this is not really a regex?)");
@@ -2242,7 +2245,7 @@
     if (argc == 1) {
       regex.reset(new RegularExpression());
       const char *arg = command.GetArgumentAtIndex(0);
-      if (!regex->Compile(arg)) {
+      if (!regex->Compile(llvm::StringRef::withNullAsEmpty(arg))) {
         result.AppendErrorWithFormat(
             "syntax error in category regular expression '%s'", arg);
         result.SetStatus(eReturnStatusFailed);
@@ -2259,9 +2262,10 @@
         [&regex, &result](const lldb::TypeCategoryImplSP &category_sp) -> bool {
           if (regex) {
             bool escape = true;
-            if (0 == strcmp(category_sp->GetName(), regex->GetText())) {
+            if (regex->GetText() == category_sp->GetName()) {
               escape = false;
-            } else if (regex->Execute(category_sp->GetName())) {
+            } else if (regex->Execute(llvm::StringRef::withNullAsEmpty(
+                           category_sp->GetName()))) {
               escape = false;
             }
 
@@ -2510,7 +2514,7 @@
 
   if (type == eRegexSynth) {
     RegularExpressionSP typeRX(new RegularExpression());
-    if (!typeRX->Compile(type_name.GetCString())) {
+    if (!typeRX->Compile(type_name.GetStringRef())) {
       if (error)
         error->SetErrorString(
             "regex format error (maybe this is not really a regex?)");
@@ -2652,7 +2656,7 @@
 
     if (type == eRegexFilter) {
       RegularExpressionSP typeRX(new RegularExpression());
-      if (!typeRX->Compile(type_name.GetCString())) {
+      if (!typeRX->Compile(type_name.GetStringRef())) {
         if (error)
           error->SetErrorString(
               "regex format error (maybe this is not really a regex?)");