123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #ifndef BASE_COMMAND_LINE_H_
- #define BASE_COMMAND_LINE_H_
- #include <stddef.h>
- #include <map>
- #include <string>
- #include <vector>
- #include "base/base_export.h"
- #include "base/strings/string16.h"
- #include "base/strings/string_piece.h"
- #include "build/build_config.h"
- namespace base {
- class FilePath;
- class BASE_EXPORT CommandLine {
- public:
- #if defined(OS_WIN)
-
- using StringType = std::wstring;
- #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- using StringType = std::string;
- #endif
- using StringPieceType = base::BasicStringPiece<StringType>;
- using CharType = StringType::value_type;
- using StringVector = std::vector<StringType>;
- using SwitchMap = std::map<std::string, StringType, std::less<>>;
-
- enum NoProgram { NO_PROGRAM };
- explicit CommandLine(NoProgram no_program);
-
- explicit CommandLine(const FilePath& program);
-
- CommandLine(int argc, const CharType* const* argv);
- explicit CommandLine(const StringVector& argv);
- CommandLine(const CommandLine& other);
- CommandLine& operator=(const CommandLine& other);
- ~CommandLine();
- #if defined(OS_WIN)
-
-
-
-
-
-
-
- static void set_slash_is_not_a_switch();
-
-
-
-
-
- static void InitUsingArgvForTesting(int argc, const char* const* argv);
- #endif
-
-
-
-
-
-
- static bool Init(int argc, const char* const* argv);
-
-
-
-
-
- static void Reset();
-
-
-
- static CommandLine* ForCurrentProcess();
-
- static bool InitializedForCurrentProcess();
- #if defined(OS_WIN)
- static CommandLine FromString(StringPieceType command_line);
- #endif
-
- void InitFromArgv(int argc, const CharType* const* argv);
- void InitFromArgv(const StringVector& argv);
-
-
-
-
-
- StringType GetCommandLineString() const;
- #if defined(OS_WIN)
-
-
-
-
-
-
-
-
-
- StringType GetCommandLineStringForShell() const;
- #endif
-
-
-
- StringType GetArgumentsString() const;
-
- const StringVector& argv() const { return argv_; }
-
- FilePath GetProgram() const;
- void SetProgram(const FilePath& program);
-
-
-
-
-
- bool HasSwitch(const StringPiece& switch_string) const;
- bool HasSwitch(const char switch_constant[]) const;
-
-
-
- std::string GetSwitchValueASCII(const StringPiece& switch_string) const;
- FilePath GetSwitchValuePath(const StringPiece& switch_string) const;
- StringType GetSwitchValueNative(const StringPiece& switch_string) const;
-
- const SwitchMap& GetSwitches() const { return switches_; }
-
-
- void AppendSwitch(const std::string& switch_string);
- void AppendSwitchPath(const std::string& switch_string,
- const FilePath& path);
- void AppendSwitchNative(const std::string& switch_string,
- StringPieceType value);
- void AppendSwitchASCII(const std::string& switch_string,
- const std::string& value);
-
-
- void RemoveSwitch(const base::StringPiece switch_key_without_prefix);
-
-
- void CopySwitchesFrom(const CommandLine& source,
- const char* const switches[],
- size_t count);
-
- StringVector GetArgs() const;
-
-
-
-
- void AppendArg(const std::string& value);
- void AppendArgPath(const FilePath& value);
- void AppendArgNative(const StringType& value);
-
-
- void AppendArguments(const CommandLine& other, bool include_program);
-
-
- void PrependWrapper(const StringType& wrapper);
- #if defined(OS_WIN)
-
-
- void ParseFromString(StringPieceType command_line);
- #endif
- private:
-
- CommandLine() = delete;
-
-
-
-
-
- void AppendSwitchesAndArguments(const StringVector& argv);
- #if defined(OS_WIN)
-
-
-
-
-
-
-
-
-
- void ParseAsSingleArgument(const StringType& single_arg_switch_string);
-
-
-
- StringPieceType raw_command_line_string_;
- #endif
-
- static CommandLine* current_process_commandline_;
-
- StringVector argv_;
-
- SwitchMap switches_;
-
- size_t begin_args_;
- };
- }
- #endif
|