Handle trailing spaces on "settings set" command more correctly
Summary:
Currently we have some settings which treat "\ " on settings set commands specially. E.g., it is
a valid way of specifying an argument of " " to a target. However, this fails if "\ " is the last
argument as CommandObjectSettingsSet strips trailing whitespace. This resulted in a surprising
argument of "\" to the target.
This patch disables the training whitespace removal at a global
level. Instead, for each argument type we locally determine whether whitespace stripping makes
sense. Currently, I strip whitespace for all simple object type except of regex and
format-string, with the rationale that these two object types do their own complex parsing and we
want to interfere with them as least as possible. Specifically, stripping the whitespace of a
regex "\ " will result in a (surprising?) error "trailing backslash". Furthermore, the default
value of dissasembly-format setting already contains a trailing space and there is no way for the
user to type this in manually if we strip whitespace.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D7592
llvm-svn: 229382
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index 4f0219f..50d3fff 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -870,26 +870,24 @@
bool
Args::StringToBoolean (const char *s, bool fail_value, bool *success_ptr)
{
- if (s && s[0])
+ llvm::StringRef ref = llvm::StringRef(s).trim();
+ if (ref.equals_lower("false") ||
+ ref.equals_lower("off") ||
+ ref.equals_lower("no") ||
+ ref.equals_lower("0"))
{
- if (::strcasecmp (s, "false") == 0 ||
- ::strcasecmp (s, "off") == 0 ||
- ::strcasecmp (s, "no") == 0 ||
- ::strcmp (s, "0") == 0)
- {
- if (success_ptr)
- *success_ptr = true;
- return false;
- }
- else
- if (::strcasecmp (s, "true") == 0 ||
- ::strcasecmp (s, "on") == 0 ||
- ::strcasecmp (s, "yes") == 0 ||
- ::strcmp (s, "1") == 0)
- {
- if (success_ptr) *success_ptr = true;
- return true;
- }
+ if (success_ptr)
+ *success_ptr = true;
+ return false;
+ }
+ else
+ if (ref.equals_lower("true") ||
+ ref.equals_lower("on") ||
+ ref.equals_lower("yes") ||
+ ref.equals_lower("1"))
+ {
+ if (success_ptr) *success_ptr = true;
+ return true;
}
if (success_ptr) *success_ptr = false;
return fail_value;