[Lldb-commits] [lldb] r131185 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/Interpreter/CommandInterpreter.cpp
Caroline Tice
ctice at apple.com
Wed May 11 09:07:07 PDT 2011
Author: ctice
Date: Wed May 11 11:07:06 2011
New Revision: 131185
URL: http://llvm.org/viewvc/llvm-project?rev=131185&view=rev
Log:
Add ability to recognize/handle quotes around commands
(e.g. '"target" create' works as well as 'target create').
Modified:
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=131185&r1=131184&r2=131185&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Wed May 11 11:07:06 2011
@@ -105,7 +105,9 @@
bool
StripFirstWord (std::string &command_string,
- std::string &next_word);
+ std::string &next_word,
+ bool &was_quoted,
+ char "e_char);
void
BuildAliasResult (const char *alias_name,
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=131185&r1=131184&r2=131185&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed May 11 11:07:06 2011
@@ -789,7 +789,7 @@
}
bool
-CommandInterpreter::StripFirstWord (std::string &command_string, std::string &word)
+CommandInterpreter::StripFirstWord (std::string &command_string, std::string &word, bool &was_quoted, char "e_char)
{
std::string white_space (" \t\v");
size_t start;
@@ -798,19 +798,48 @@
start = command_string.find_first_not_of (white_space);
if (start != std::string::npos)
{
- end = command_string.find_first_of (white_space, start);
- if (end != std::string::npos)
- {
- word = command_string.substr (start, end - start);
- command_string = command_string.substr (end);
- size_t pos = command_string.find_first_not_of (white_space);
- if ((pos != 0) && (pos != std::string::npos))
- command_string = command_string.substr (pos);
+ size_t len = command_string.size() - start;
+ if (len >= 2
+ && ((command_string[start] == '\'') || (command_string[start] == '"')))
+ {
+ was_quoted = true;
+ quote_char = command_string[start];
+ std::string quote_string = command_string.substr (start, 1);
+ start = start + 1;
+ end = command_string.find (quote_string, start);
+ if (end != std::string::npos)
+ {
+ word = command_string.substr (start, end - start);
+ if (end + 1 < len)
+ command_string = command_string.substr (end+1);
+ else
+ command_string.erase ();
+ size_t pos = command_string.find_first_not_of (white_space);
+ if ((pos != 0) && (pos != std::string::npos))
+ command_string = command_string.substr (pos);
+ }
+ else
+ {
+ word = command_string.substr (start - 1);
+ command_string.erase ();
+ }
}
else
{
- word = command_string.substr (start);
- command_string.erase();
+ end = command_string.find_first_of (white_space, start);
+ if (end != std::string::npos)
+ {
+ word = command_string.substr (start, end - start);
+ command_string = command_string.substr (end);
+ size_t pos = command_string.find_first_not_of (white_space);
+ if ((pos != 0) && (pos != std::string::npos))
+ command_string = command_string.substr (pos);
+ }
+ else
+ {
+ word = command_string.substr (start);
+ command_string.erase();
+ }
}
}
@@ -964,7 +993,7 @@
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return true;
}
-
+
// Phase 1.
// Before we do ANY kind of argument processing, etc. we need to figure out what the real/final command object
@@ -979,7 +1008,9 @@
size_t actual_cmd_name_len = 0;
while (!done)
{
- StripFirstWord (command_string, next_word);
+ bool was_quoted = false;
+ char quote_char = '\0';
+ StripFirstWord (command_string, next_word, was_quoted, quote_char);
if (!cmd_obj && AliasExists (next_word.c_str()))
{
std::string alias_result;
@@ -1017,13 +1048,29 @@
}
else
{
- revised_command_line.Printf (" %s", next_word.c_str());
+ if (was_quoted)
+ {
+ if (quote_char == '"')
+ revised_command_line.Printf (" \"%s\"", next_word.c_str());
+ else
+ revised_command_line.Printf (" '%s'", next_word.c_str());
+ }
+ else
+ revised_command_line.Printf (" %s", next_word.c_str());
done = true;
}
}
else
{
- revised_command_line.Printf (" %s", next_word.c_str());
+ if (was_quoted)
+ {
+ if (quote_char == '"')
+ revised_command_line.Printf (" \"%s\"", next_word.c_str());
+ else
+ revised_command_line.Printf (" '%s'", next_word.c_str());
+ }
+ else
+ revised_command_line.Printf (" %s", next_word.c_str());
done = true;
}
More information about the lldb-commits
mailing list