OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #elif defined(OS_POSIX) | 10 #elif defined(OS_POSIX) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 #endif | 47 #endif |
48 | 48 |
49 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
50 // Lowercase a string. This is used to lowercase switch names. | 50 // Lowercase a string. This is used to lowercase switch names. |
51 // Is this what we really want? It seems crazy to me. I've left it in | 51 // Is this what we really want? It seems crazy to me. I've left it in |
52 // for backwards compatibility on Windows. | 52 // for backwards compatibility on Windows. |
53 static void Lowercase(std::string* parameter) { | 53 static void Lowercase(std::string* parameter) { |
54 transform(parameter->begin(), parameter->end(), parameter->begin(), | 54 transform(parameter->begin(), parameter->end(), parameter->begin(), |
55 tolower); | 55 tolower); |
56 } | 56 } |
57 #endif | 57 |
58 // Trims the quotes from the beginning and end of a path. | |
59 CommandLine::StringType TrimQuotes(const FilePath::StringType& path) { | |
60 if (!path.empty() && path[0] == '"' && path[path.length() - 1] == '"') | |
61 return path.substr(1, path.length() - 2); | |
62 return path; | |
63 } | |
64 #endif // defined(OS_WIN) | |
58 | 65 |
59 CommandLine::~CommandLine() { | 66 CommandLine::~CommandLine() { |
60 } | 67 } |
61 | 68 |
62 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
63 CommandLine::CommandLine(NoProgram no_program) { | 70 CommandLine::CommandLine(NoProgram no_program) { |
64 } | 71 } |
65 | 72 |
66 void CommandLine::ParseFromString(const std::wstring& command_line) { | 73 void CommandLine::ParseFromString(const std::wstring& command_line) { |
67 TrimWhitespace(command_line, TRIM_ALL, &command_line_string_); | 74 TrimWhitespace(command_line, TRIM_ALL, &command_line_string_); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 114 |
108 // static | 115 // static |
109 CommandLine CommandLine::FromString(const std::wstring& command_line) { | 116 CommandLine CommandLine::FromString(const std::wstring& command_line) { |
110 CommandLine cmd; | 117 CommandLine cmd; |
111 cmd.ParseFromString(command_line); | 118 cmd.ParseFromString(command_line); |
112 return cmd; | 119 return cmd; |
113 } | 120 } |
114 | 121 |
115 CommandLine::CommandLine(const FilePath& program) { | 122 CommandLine::CommandLine(const FilePath& program) { |
116 if (!program.empty()) { | 123 if (!program.empty()) { |
117 program_ = program.value(); | 124 program_ = TrimQuotes(program.value()); |
Evan Martin
2010/11/15 22:21:57
To be clear, if there are quotes here something ha
tommi (sloooow) - chröme
2010/11/15 22:41:23
I think so, yes. However I cleaned up quite a bit
| |
118 // TODO(evanm): proper quoting here. | 125 // TODO(evanm): proper quoting here. |
119 command_line_string_ = L'"' + program.value() + L'"'; | 126 command_line_string_ = L'"' + program_ + L'"'; |
120 } | 127 } |
121 } | 128 } |
122 | 129 |
123 #elif defined(OS_POSIX) | 130 #elif defined(OS_POSIX) |
124 CommandLine::CommandLine(NoProgram no_program) { | 131 CommandLine::CommandLine(NoProgram no_program) { |
125 // Push an empty argument, because we always assume argv_[0] is a program. | 132 // Push an empty argument, because we always assume argv_[0] is a program. |
126 argv_.push_back(""); | 133 argv_.push_back(""); |
127 } | 134 } |
128 | 135 |
129 CommandLine::CommandLine(int argc, const char* const* argv) { | 136 CommandLine::CommandLine(int argc, const char* const* argv) { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 | 542 |
536 // private | 543 // private |
537 CommandLine::CommandLine() { | 544 CommandLine::CommandLine() { |
538 } | 545 } |
539 | 546 |
540 // static | 547 // static |
541 CommandLine* CommandLine::ForCurrentProcessMutable() { | 548 CommandLine* CommandLine::ForCurrentProcessMutable() { |
542 DCHECK(current_process_commandline_); | 549 DCHECK(current_process_commandline_); |
543 return current_process_commandline_; | 550 return current_process_commandline_; |
544 } | 551 } |
OLD | NEW |