[Lldb-commits] [lldb] r371181 - [lldb][NFC] Remove Args::StripSpaces

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 6 01:40:31 PDT 2019


Author: teemperor
Date: Fri Sep  6 01:40:31 2019
New Revision: 371181

URL: http://llvm.org/viewvc/llvm-project?rev=371181&view=rev
Log:
[lldb][NFC] Remove Args::StripSpaces

This just reimplemented llvm::StringRef::[r/l]trim().

Modified:
    lldb/trunk/include/lldb/Utility/Args.h
    lldb/trunk/source/Commands/CommandObjectSettings.cpp
    lldb/trunk/source/Expression/REPL.cpp
    lldb/trunk/source/Utility/Args.cpp

Modified: lldb/trunk/include/lldb/Utility/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Args.h?rev=371181&r1=371180&r2=371181&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Args.h (original)
+++ lldb/trunk/include/lldb/Utility/Args.h Fri Sep  6 01:40:31 2019
@@ -251,10 +251,6 @@ public:
   // For re-setting or blanking out the list of arguments.
   void Clear();
 
-  static const char *StripSpaces(std::string &s, bool leading = true,
-                                 bool trailing = true,
-                                 bool return_null_if_empty = true);
-
   static bool UInt64ValueIsValidForByteSize(uint64_t uval64,
                                             size_t total_byte_size) {
     if (total_byte_size > 8)

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=371181&r1=371180&r2=371181&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Fri Sep  6 01:40:31 2019
@@ -205,16 +205,13 @@ protected:
     }
 
     // Split the raw command into var_name and value pair.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, false, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.ltrim();
 
     Status error;
-    if (m_options.m_global) {
+    if (m_options.m_global)
       error = GetDebugger().SetPropertyValue(nullptr, eVarSetOperationAssign,
-                                             var_name, var_value_cstr);
-    }
+                                             var_name, var_value);
 
     if (error.Success()) {
       // FIXME this is the same issue as the one in commands script import
@@ -225,7 +222,7 @@ protected:
       ExecutionContext exe_ctx(m_exe_ctx);
       m_exe_ctx.Clear();
       error = GetDebugger().SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
-                                             var_name, var_value_cstr);
+                                             var_name, var_value);
     }
 
     if (error.Fail()) {
@@ -646,13 +643,11 @@ protected:
     }
 
     // Split the raw command into var_name and value pair.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, true, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.trim();
 
     Status error(GetDebugger().SetPropertyValue(
-        &m_exe_ctx, eVarSetOperationRemove, var_name, var_value_cstr));
+        &m_exe_ctx, eVarSetOperationRemove, var_name, var_value));
     if (error.Fail()) {
       result.AppendError(error.AsCString());
       result.SetStatus(eReturnStatusFailed);
@@ -744,13 +739,11 @@ protected:
     }
 
     // Split the raw command into var_name, index_value, and value triple.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, true, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.trim();
 
     Status error(GetDebugger().SetPropertyValue(
-        &m_exe_ctx, eVarSetOperationReplace, var_name, var_value_cstr));
+        &m_exe_ctx, eVarSetOperationReplace, var_name, var_value));
     if (error.Fail()) {
       result.AppendError(error.AsCString());
       result.SetStatus(eReturnStatusFailed);
@@ -848,13 +841,11 @@ protected:
     }
 
     // Split the raw command into var_name, index_value, and value triple.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, true, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.trim();
 
     Status error(GetDebugger().SetPropertyValue(
-        &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value_cstr));
+        &m_exe_ctx, eVarSetOperationInsertBefore, var_name, var_value));
     if (error.Fail()) {
       result.AppendError(error.AsCString());
       result.SetStatus(eReturnStatusFailed);
@@ -949,13 +940,11 @@ protected:
     }
 
     // Split the raw command into var_name, index_value, and value triple.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, true, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.trim();
 
     Status error(GetDebugger().SetPropertyValue(
-        &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value_cstr));
+        &m_exe_ctx, eVarSetOperationInsertAfter, var_name, var_value));
     if (error.Fail()) {
       result.AppendError(error.AsCString());
       result.SetStatus(eReturnStatusFailed);
@@ -1041,13 +1030,11 @@ protected:
     // character string later on.
 
     // Split the raw command into var_name and value pair.
-    llvm::StringRef raw_str(command);
-    std::string var_value_string = raw_str.split(var_name).second.str();
-    const char *var_value_cstr =
-        Args::StripSpaces(var_value_string, true, true, false);
+    llvm::StringRef var_value(command);
+    var_value = var_value.split(var_name).second.trim();
 
     Status error(GetDebugger().SetPropertyValue(
-        &m_exe_ctx, eVarSetOperationAppend, var_name, var_value_cstr));
+        &m_exe_ctx, eVarSetOperationAppend, var_name, var_value));
     if (error.Fail()) {
       result.AppendError(error.AsCString());
       result.SetStatus(eReturnStatusFailed);

Modified: lldb/trunk/source/Expression/REPL.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/REPL.cpp?rev=371181&r1=371180&r2=371181&view=diff
==============================================================================
--- lldb/trunk/source/Expression/REPL.cpp (original)
+++ lldb/trunk/source/Expression/REPL.cpp Fri Sep  6 01:40:31 2019
@@ -206,7 +206,7 @@ void REPL::IOHandlerInputComplete(IOHand
       // Meta command
       // Strip the ':'
       code.erase(0, 1);
-      if (Args::StripSpaces(code)) {
+      if (!llvm::StringRef(code).trim().empty()) {
         // "lldb" was followed by arguments, so just execute the command dump
         // the results
 

Modified: lldb/trunk/source/Utility/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Args.cpp?rev=371181&r1=371180&r2=371181&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Args.cpp (original)
+++ lldb/trunk/source/Utility/Args.cpp Fri Sep  6 01:40:31 2019
@@ -382,29 +382,6 @@ void Args::Clear() {
   m_argv.push_back(nullptr);
 }
 
-const char *Args::StripSpaces(std::string &s, bool leading, bool trailing,
-                              bool return_null_if_empty) {
-  static const char *k_white_space = " \t\v";
-  if (!s.empty()) {
-    if (leading) {
-      size_t pos = s.find_first_not_of(k_white_space);
-      if (pos == std::string::npos)
-        s.clear();
-      else if (pos > 0)
-        s.erase(0, pos);
-    }
-
-    if (trailing) {
-      size_t rpos = s.find_last_not_of(k_white_space);
-      if (rpos != std::string::npos && rpos + 1 < s.size())
-        s.erase(rpos + 1);
-    }
-  }
-  if (return_null_if_empty && s.empty())
-    return nullptr;
-  return s.c_str();
-}
-
 const char *Args::GetShellSafeArgument(const FileSpec &shell,
                                        const char *unsafe_arg,
                                        std::string &safe_arg) {




More information about the lldb-commits mailing list