From 7841e80e79f231d564bf9f849c8e3cad171b7ba4 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Fri, 6 Sep 2019 08:40:31 +0000 Subject: [PATCH] [lldb][NFC] Remove Args::StripSpaces This just reimplemented llvm::StringRef::[r/l]trim(). llvm-svn: 371181 --- lldb/include/lldb/Utility/Args.h | 4 -- lldb/source/Commands/CommandObjectSettings.cpp | 53 ++++++++++---------------- lldb/source/Expression/REPL.cpp | 2 +- lldb/source/Utility/Args.cpp | 23 ----------- 4 files changed, 21 insertions(+), 61 deletions(-) diff --git a/lldb/include/lldb/Utility/Args.h b/lldb/include/lldb/Utility/Args.h index 5b2f16e..bc21d39 100644 --- a/lldb/include/lldb/Utility/Args.h +++ b/lldb/include/lldb/Utility/Args.h @@ -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) diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 5f6a4dc..8c62bea 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -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); diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index 01350f3..7935251 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -206,7 +206,7 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) { // 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 diff --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp index 64577be..1251698 100644 --- a/lldb/source/Utility/Args.cpp +++ b/lldb/source/Utility/Args.cpp @@ -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) { -- 2.7.4