[Lldb-commits] [lldb] r142888 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h source/Interpreter/CommandInterpreter.cpp
Greg Clayton
gclayton at apple.com
Mon Oct 24 17:36:27 PDT 2011
Author: gclayton
Date: Mon Oct 24 19:36:27 2011
New Revision: 142888
URL: http://llvm.org/viewvc/llvm-project?rev=142888&view=rev
Log:
Simplified the CommandInterpreter::StripFirstWord logic by making it a static
function and having it not require both a bool and a quote char to fill in.
We intend to get rid of this functionality when we rewrite the command
interpreter for streams eventually, but not for now.
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=142888&r1=142887&r2=142888&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Mon Oct 24 19:36:27 2011
@@ -129,12 +129,6 @@
AddOrReplaceAliasOptions (const char *alias_name,
OptionArgVectorSP &option_arg_vector_sp);
- bool
- StripFirstWord (std::string &command_string,
- std::string &next_word,
- bool &was_quoted,
- char "e_char);
-
void
BuildAliasResult (const char *alias_name,
std::string &raw_input_string,
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=142888&r1=142887&r2=142888&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Mon Oct 24 19:36:27 2011
@@ -878,62 +878,70 @@
return cmd_obj;
}
-bool
-CommandInterpreter::StripFirstWord (std::string &command_string, std::string &word, bool &was_quoted, char "e_char)
+static const char *k_white_space = " \t\v";
+
+static void
+StripLeadingSpaces (std::string &s)
{
- std::string white_space (" \t\v");
- size_t start;
- size_t end;
-
- start = command_string.find_first_not_of (white_space);
- if (start != std::string::npos)
- {
- 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);
+ if (!s.empty())
+ {
+ size_t pos = s.find_first_not_of (k_white_space);
+ if (pos == std::string::npos)
+ s.clear();
+ else if (pos == 0)
+ return;
+ s.erase (0, pos);
+ }
+}
+
+static bool
+StripFirstWord (std::string &command_string, std::string &word, char "e_char)
+{
+ word.clear();
+ StripLeadingSpaces (command_string);
+
+ bool result = false;
+ quote_char = '\0';
+
+ if (!command_string.empty())
+ {
+ const char first_char = command_string[0];
+ if (first_char == '\'' || first_char == '"')
+ {
+ quote_char = first_char;
+ const size_t end_quote_pos = command_string.find (quote_char, 1);
+ if (end_quote_pos == std::string::npos)
+ {
+ word.swap (command_string);
+ command_string.erase ();
}
else
{
- word = command_string.substr (start - 1);
- command_string.erase ();
+ word = command_string.substr (1, end_quote_pos - 1);
+ if (end_quote_pos + 1 < command_string.size())
+ command_string.erase (0, command_string.find_first_not_of (k_white_space, end_quote_pos + 1));
+ else
+ command_string.erase ();
}
}
else
{
- end = command_string.find_first_of (white_space, start);
- if (end != std::string::npos)
+ const size_t first_space_pos = command_string.find_first_of (k_white_space);
+ if (first_space_pos == 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);
+ word.swap (command_string);
+ command_string.erase();
}
else
{
- word = command_string.substr (start);
- command_string.erase();
+ word = command_string.substr (0, first_space_pos);
+ command_string.erase(0,command_string.find_first_not_of (k_white_space, first_space_pos));
}
}
-
+ result = true;
}
- return true;
+
+ return result;
}
void
@@ -1236,9 +1244,8 @@
size_t actual_cmd_name_len = 0;
while (!done)
{
- bool was_quoted = false;
char quote_char = '\0';
- StripFirstWord (command_string, next_word, was_quoted, quote_char);
+ StripFirstWord (command_string, next_word, quote_char);
if (!cmd_obj && AliasExists (next_word.c_str()))
{
std::string alias_result;
@@ -1276,13 +1283,8 @@
}
else
{
- 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());
- }
+ if (quote_char)
+ revised_command_line.Printf (" %c%s%c", quote_char, next_word.c_str(), quote_char);
else
revised_command_line.Printf (" %s", next_word.c_str());
done = true;
@@ -1290,13 +1292,8 @@
}
else
{
- 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());
- }
+ if (quote_char)
+ revised_command_line.Printf (" %c%s%c", quote_char, next_word.c_str(), quote_char);
else
revised_command_line.Printf (" %s", next_word.c_str());
done = true;
More information about the lldb-commits
mailing list