summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/UserSettingsController.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-12-19 03:41:24 +0000
committerGreg Clayton <gclayton@apple.com>2010-12-19 03:41:24 +0000
commit6ad07dd9e91c69f748e8aa41f6c48b0a3d3f03c0 (patch)
treefec686dfc493a7b7510421ee1049e882bf8eb128 /lldb/source/Core/UserSettingsController.cpp
parent9a2d4e04c71e87e0dedf6f4b865f4c639989afb9 (diff)
downloadbcm5719-llvm-6ad07dd9e91c69f748e8aa41f6c48b0a3d3f03c0.tar.gz
bcm5719-llvm-6ad07dd9e91c69f748e8aa41f6c48b0a3d3f03c0.zip
Improved our argument parsing abilities to be able to handle stuff more like
a shell would interpret it. A few examples that we now handle correctly INPUT: "Hello "world OUTPUT: "Hello World" INPUT: "Hello "' World' OUTPUT: "Hello World" INPUT: Hello" World" OUTPUT: "Hello World" This broke the setting of dictionary values for the "settings set" command for things like: (lldb) settings set target.process.env-vars ["MY_ENV_VAR"]=YES since we would drop the quotes. I fixed the user settings controller to use a regular expression so it can accept any of the following inputs for dictionary setting: settings set target.process.env-vars ["MY_ENV_VAR"]=YES settings set target.process.env-vars [MY_ENV_VAR]=YES settings set target.process.env-vars MY_ENV_VAR=YES We might want to eventually drop the first two syntaxes, but I won't make that decision right now. This allows more natural setting of the envirorment variables: settings set target.process.env-vars MY_ENV_VAR=YES ABC=DEF CWD=/tmp llvm-svn: 122166
Diffstat (limited to 'lldb/source/Core/UserSettingsController.cpp')
-rw-r--r--lldb/source/Core/UserSettingsController.cpp45
1 files changed, 22 insertions, 23 deletions
diff --git a/lldb/source/Core/UserSettingsController.cpp b/lldb/source/Core/UserSettingsController.cpp
index fc8d1aab57f..6cd1f3ccfd8 100644
--- a/lldb/source/Core/UserSettingsController.cpp
+++ b/lldb/source/Core/UserSettingsController.cpp
@@ -12,6 +12,7 @@
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Core/Error.h"
+#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -2102,34 +2103,32 @@ UserSettingsController::UpdateDictionaryVariable (lldb::VarSetOperationType op,
}
Args args (new_value);
size_t num_args = args.GetArgumentCount();
+ RegularExpression regex("(\\[\"?)?" // Regex match 1 (optional key prefix of '["' pr '[')
+ "([A-Za-z_][A-Za-z_0-9]*)" // Regex match 2 (key string)
+ "(\"?\\])?" // Regex match 3 (optional key suffix of '"]' pr ']')
+ "=" // The equal sign that is required
+ "(.*)"); // Regex match 4 (value string)
+ std::string key, value;
+
for (size_t i = 0; i < num_args; ++i)
{
- std::string tmp_arg = args.GetArgumentAtIndex (i);
- size_t eq_sign = tmp_arg.find ('=');
- if (eq_sign != std::string::npos)
+ const char *key_equal_value_arg = args.GetArgumentAtIndex (i);
+ // Execute the regular expression on each arg.
+ if (regex.Execute(key_equal_value_arg, 5))
{
- if (eq_sign > 4)
- {
- std::string tmp_key = tmp_arg.substr (0, eq_sign);
- std::string real_value = tmp_arg.substr (eq_sign+1);
- if ((tmp_key[0] == '[')
- && (tmp_key[1] == '"')
- && (tmp_key[eq_sign-2] == '"')
- && (tmp_key[eq_sign-1] == ']'))
- {
- std::string real_key = tmp_key.substr (2, eq_sign-4);
- dictionary[real_key] = real_value;
- }
- else
- err.SetErrorString ("Invalid key format for dictionary assignment. "
- "Expected '[\"<key>\"]'\n");
- }
- else
- err.SetErrorString ("Invalid key format for dictionary assignment. "
- "Expected '[\"<key>\"]'\n");
+ // The regular expression succeeded. The match at index
+ // zero will be the entire string that matched the entire
+ // regular expression. The match at index 1 - 4 will be
+ // as mentioned above by the creation of the regex pattern.
+ // Match index 2 is the key, match index 4 is the value.
+ regex.GetMatchAtIndex (key_equal_value_arg, 2, key);
+ regex.GetMatchAtIndex (key_equal_value_arg, 4, value);
+ dictionary[key] = value;
}
else
- err.SetErrorString ("Invalid format for dictionary value. Expected '[\"<key>\"]=<value>'\n");
+ {
+ err.SetErrorString ("Invalid format for dictionary value. Expected one of '[\"<key>\"]=<value>', '[<key>]=<value>', or '<key>=<value>'\n");
+ }
}
}
break;
OpenPOWER on IntegriCloud