summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc19
-rw-r--r--base/command_line.h12
-rw-r--r--base/command_line_unittest.cc20
3 files changed, 20 insertions, 31 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 2a7824d..c046125 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -82,7 +82,7 @@ void CommandLine::ParseFromString(const std::wstring& command_line) {
TrimWhitespace(args[i], TRIM_ALL, &arg);
if (!parse_switches) {
- loose_values_.push_back(arg);
+ args_.push_back(arg);
continue;
}
@@ -96,7 +96,7 @@ void CommandLine::ParseFromString(const std::wstring& command_line) {
if (IsSwitch(arg, &switch_string, &switch_value)) {
switches_[switch_string] = switch_value;
} else {
- loose_values_.push_back(arg);
+ args_.push_back(arg);
}
}
@@ -130,7 +130,7 @@ void CommandLine::InitFromArgv(const std::vector<std::string>& argv) {
const std::string& arg = argv_[i];
if (!parse_switches) {
- loose_values_.push_back(arg);
+ args_.push_back(arg);
continue;
}
@@ -144,7 +144,7 @@ void CommandLine::InitFromArgv(const std::vector<std::string>& argv) {
if (IsSwitch(arg, &switch_string, &switch_value)) {
switches_[switch_string] = switch_value;
} else {
- loose_values_.push_back(arg);
+ args_.push_back(arg);
}
}
}
@@ -287,19 +287,10 @@ std::wstring CommandLine::GetSwitchValue(
}
#if defined(OS_WIN)
-std::vector<std::wstring> CommandLine::GetLooseValues() const {
- return loose_values_;
-}
std::wstring CommandLine::program() const {
return program_;
}
#else
-std::vector<std::wstring> CommandLine::GetLooseValues() const {
- std::vector<std::wstring> values;
- for (size_t i = 0; i < loose_values_.size(); ++i)
- values.push_back(base::SysNativeMBToWide(loose_values_[i]));
- return values;
-}
std::wstring CommandLine::program() const {
DCHECK_GT(argv_.size(), 0U);
return base::SysNativeMBToWide(argv_[0]);
@@ -375,7 +366,7 @@ void CommandLine::AppendLooseValue(const std::wstring& value) {
// TODO(evan): quoting?
command_line_string_.append(L" ");
command_line_string_.append(value);
- loose_values_.push_back(value);
+ args_.push_back(value);
}
void CommandLine::AppendArguments(const CommandLine& other,
diff --git a/base/command_line.h b/base/command_line.h
index c68711a..2c4f32d 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -5,10 +5,9 @@
// This class works with command lines: building and parsing.
// Switches can optionally have a value attached using an equals sign,
// as in "-switch=value". Arguments that aren't prefixed with a
-// switch prefix are considered "loose parameters". Switch names are
-// case-insensitive. An argument of "--" will terminate switch
-// parsing, causing everything after to be considered as loose
-// parameters.
+// switch prefix are saved as extra arguments. An argument of "--"
+// will terminate switch parsing, causing everything after to be
+// considered as extra arguments.
// There is a singleton read-only CommandLine that represents the command
// line that the current process was started with. It must be initialized
@@ -139,8 +138,7 @@ class CommandLine {
}
// Get the remaining arguments to the command.
- // WARNING: this is incorrect on POSIX; we must do string conversions.
- std::vector<std::wstring> GetLooseValues() const;
+ const std::vector<StringType>& args() const { return args_; }
#if defined(OS_WIN)
// Returns the original command line string.
@@ -239,7 +237,7 @@ class CommandLine {
SwitchMap switches_;
// Non-switch command-line arguments.
- std::vector<StringType> loose_values_;
+ std::vector<StringType> args_;
// We allow copy constructors, because a common pattern is to grab a
// copy of the current process's command line and then add some
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index 6544c13..8f3c7c0 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -59,21 +59,21 @@ TEST(CommandLineTest, CommandLineConstructor) {
"other-switches"));
EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));
- std::vector<std::wstring> loose_values = cl.GetLooseValues();
- ASSERT_EQ(5U, loose_values.size());
+ const std::vector<CommandLine::StringType>& args = cl.args();
+ ASSERT_EQ(5U, args.size());
- std::vector<std::wstring>::const_iterator iter = loose_values.begin();
- EXPECT_EQ(L"flim", *iter);
+ std::vector<CommandLine::StringType>::const_iterator iter = args.begin();
+ EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter);
++iter;
- EXPECT_EQ(L"flan", *iter);
+ EXPECT_EQ(FILE_PATH_LITERAL("flan"), *iter);
++iter;
- EXPECT_EQ(L"--", *iter);
+ EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter);
++iter;
- EXPECT_EQ(L"--not-a-switch", *iter);
+ EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter);
++iter;
- EXPECT_EQ(L"in the time of submarines...", *iter);
+ EXPECT_EQ(FILE_PATH_LITERAL("in the time of submarines..."), *iter);
++iter;
- EXPECT_TRUE(iter == loose_values.end());
+ EXPECT_TRUE(iter == args.end());
#if defined(OS_POSIX)
const std::vector<std::string>& argvec = cl.argv();
@@ -93,7 +93,7 @@ TEST(CommandLineTest, EmptyString) {
CommandLine cl(0, NULL);
EXPECT_TRUE(cl.argv().size() == 0);
#endif
- EXPECT_EQ(0U, cl.GetLooseValues().size());
+ EXPECT_EQ(0U, cl.args().size());
}
// Test methods for appending switches to a command line.