| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #endif | 10 #endif |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 std::string switch_value; | 120 std::string switch_value; |
| 121 if (IsSwitch(arg, &switch_string, &switch_value)) { | 121 if (IsSwitch(arg, &switch_string, &switch_value)) { |
| 122 switches_[switch_string] = switch_value; | 122 switches_[switch_string] = switch_value; |
| 123 } else { | 123 } else { |
| 124 loose_values_.push_back(arg); | 124 loose_values_.push_back(arg); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 CommandLine::CommandLine(const std::wstring& program) { | 129 CommandLine::CommandLine(const std::wstring& program) { |
| 130 argv_.push_back(WideToASCII(program)); | 130 argv_.push_back(base::SysWideToNativeMB(program)); |
| 131 } | 131 } |
| 132 #endif | 132 #endif |
| 133 | 133 |
| 134 // static | 134 // static |
| 135 bool CommandLine::IsSwitch(const StringType& parameter_string, | 135 bool CommandLine::IsSwitch(const StringType& parameter_string, |
| 136 std::string* switch_string, | 136 std::string* switch_string, |
| 137 StringType* switch_value) { | 137 StringType* switch_value) { |
| 138 switch_string->clear(); | 138 switch_string->clear(); |
| 139 switch_value->clear(); | 139 switch_value->clear(); |
| 140 | 140 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 std::map<std::string, StringType>::const_iterator result = | 218 std::map<std::string, StringType>::const_iterator result = |
| 219 switches_.find(WideToASCII(lowercased_switch)); | 219 switches_.find(WideToASCII(lowercased_switch)); |
| 220 | 220 |
| 221 if (result == switches_.end()) { | 221 if (result == switches_.end()) { |
| 222 return L""; | 222 return L""; |
| 223 } else { | 223 } else { |
| 224 #if defined(OS_WIN) | 224 #if defined(OS_WIN) |
| 225 return result->second; | 225 return result->second; |
| 226 #else | 226 #else |
| 227 return ASCIIToWide(result->second); | 227 return base::SysNativeMBToWide(result->second); |
| 228 #endif | 228 #endif |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 #if defined(OS_WIN) | 232 #if defined(OS_WIN) |
| 233 std::vector<std::wstring> CommandLine::GetLooseValues() const { | 233 std::vector<std::wstring> CommandLine::GetLooseValues() const { |
| 234 return loose_values_; | 234 return loose_values_; |
| 235 } | 235 } |
| 236 std::wstring CommandLine::program() const { | 236 std::wstring CommandLine::program() const { |
| 237 return program_; | 237 return program_; |
| 238 } | 238 } |
| 239 #else | 239 #else |
| 240 std::vector<std::wstring> CommandLine::GetLooseValues() const { | 240 std::vector<std::wstring> CommandLine::GetLooseValues() const { |
| 241 std::vector<std::wstring> values; | 241 std::vector<std::wstring> values; |
| 242 for (size_t i = 0; i < loose_values_.size(); ++i) | 242 for (size_t i = 0; i < loose_values_.size(); ++i) |
| 243 values.push_back(ASCIIToWide(loose_values_[i])); | 243 values.push_back(base::SysNativeMBToWide(loose_values_[i])); |
| 244 return values; | 244 return values; |
| 245 } | 245 } |
| 246 std::wstring CommandLine::program() const { | 246 std::wstring CommandLine::program() const { |
| 247 DCHECK(argv_.size() > 0); | 247 DCHECK(argv_.size() > 0); |
| 248 return ASCIIToWide(argv_[0]); | 248 return base::SysNativeMBToWide(argv_[0]); |
| 249 } | 249 } |
| 250 #endif | 250 #endif |
| 251 | 251 |
| 252 | 252 |
| 253 // static | 253 // static |
| 254 std::wstring CommandLine::PrefixedSwitchString( | 254 std::wstring CommandLine::PrefixedSwitchString( |
| 255 const std::wstring& switch_string) { | 255 const std::wstring& switch_string) { |
| 256 return StringPrintf(L"%ls%ls", | 256 return StringPrintf(L"%ls%ls", |
| 257 kSwitchPrefixes[0], | 257 kSwitchPrefixes[0], |
| 258 switch_string.c_str()); | 258 switch_string.c_str()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 #elif defined(OS_POSIX) | 334 #elif defined(OS_POSIX) |
| 335 void CommandLine::AppendSwitch(const std::wstring& switch_string) { | 335 void CommandLine::AppendSwitch(const std::wstring& switch_string) { |
| 336 std::string ascii_switch = WideToASCII(switch_string); | 336 std::string ascii_switch = WideToASCII(switch_string); |
| 337 argv_.push_back(kSwitchPrefixes[0] + ascii_switch); | 337 argv_.push_back(kSwitchPrefixes[0] + ascii_switch); |
| 338 switches_[ascii_switch] = ""; | 338 switches_[ascii_switch] = ""; |
| 339 } | 339 } |
| 340 | 340 |
| 341 void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string, | 341 void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string, |
| 342 const std::wstring& value_string) { | 342 const std::wstring& value_string) { |
| 343 std::string ascii_switch = WideToASCII(switch_string); | 343 std::string ascii_switch = WideToASCII(switch_string); |
| 344 std::string ascii_value = WideToASCII(value_string); | 344 std::string mb_value = base::SysWideToNativeMB(value_string); |
| 345 | 345 |
| 346 argv_.push_back(kSwitchPrefixes[0] + ascii_switch + | 346 argv_.push_back(kSwitchPrefixes[0] + ascii_switch + |
| 347 kSwitchValueSeparator + ascii_value); | 347 kSwitchValueSeparator + mb_value); |
| 348 switches_[ascii_switch] = ascii_value; | 348 switches_[ascii_switch] = mb_value; |
| 349 } | 349 } |
| 350 | 350 |
| 351 void CommandLine::AppendLooseValue(const std::wstring& value) { | 351 void CommandLine::AppendLooseValue(const std::wstring& value) { |
| 352 argv_.push_back(WideToASCII(value)); | 352 argv_.push_back(base::SysWideToNativeMB(value)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void CommandLine::AppendArguments(const CommandLine& other, | 355 void CommandLine::AppendArguments(const CommandLine& other, |
| 356 bool include_program) { | 356 bool include_program) { |
| 357 // Verify include_program is used correctly. | 357 // Verify include_program is used correctly. |
| 358 // Logic could be shorter but this is clearer. | 358 // Logic could be shorter but this is clearer. |
| 359 DCHECK(include_program ? !other.program().empty() : other.program().empty()); | 359 DCHECK(include_program ? !other.program().empty() : other.program().empty()); |
| 360 | 360 |
| 361 size_t first_arg = include_program ? 0 : 1; | 361 size_t first_arg = include_program ? 0 : 1; |
| 362 for (size_t i = first_arg; i < other.argv_.size(); ++i) | 362 for (size_t i = first_arg; i < other.argv_.size(); ++i) |
| 363 argv_.push_back(other.argv_[i]); | 363 argv_.push_back(other.argv_[i]); |
| 364 std::map<std::string, StringType>::const_iterator i; | 364 std::map<std::string, StringType>::const_iterator i; |
| 365 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) | 365 for (i = other.switches_.begin(); i != other.switches_.end(); ++i) |
| 366 switches_[i->first] = i->second; | 366 switches_[i->first] = i->second; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void CommandLine::PrependWrapper(const std::wstring& wrapper_wide) { | 369 void CommandLine::PrependWrapper(const std::wstring& wrapper_wide) { |
| 370 // The wrapper may have embedded arguments (like "gdb --args"). In this case, | 370 // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
| 371 // we don't pretend to do anything fancy, we just split on spaces. | 371 // we don't pretend to do anything fancy, we just split on spaces. |
| 372 const std::string wrapper = WideToASCII(wrapper_wide); | 372 const std::string wrapper = base::SysWideToNativeMB(wrapper_wide); |
| 373 std::vector<std::string> wrapper_and_args; | 373 std::vector<std::string> wrapper_and_args; |
| 374 SplitString(wrapper, ' ', &wrapper_and_args); | 374 SplitString(wrapper, ' ', &wrapper_and_args); |
| 375 argv_.insert(argv_.begin(), wrapper_and_args.begin(), wrapper_and_args.end()); | 375 argv_.insert(argv_.begin(), wrapper_and_args.begin(), wrapper_and_args.end()); |
| 376 } | 376 } |
| 377 | 377 |
| 378 #endif | 378 #endif |
| OLD | NEW |