Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Common/CommandLineParser.h |
michael@0 | 2 | |
michael@0 | 3 | #ifndef __COMMON_COMMANDLINEPARSER_H |
michael@0 | 4 | #define __COMMON_COMMANDLINEPARSER_H |
michael@0 | 5 | |
michael@0 | 6 | #include "Common/String.h" |
michael@0 | 7 | |
michael@0 | 8 | namespace NCommandLineParser { |
michael@0 | 9 | |
michael@0 | 10 | void SplitCommandLine(const UString &src, UString &dest1, UString &dest2); |
michael@0 | 11 | void SplitCommandLine(const UString &s, UStringVector &parts); |
michael@0 | 12 | |
michael@0 | 13 | namespace NSwitchType { |
michael@0 | 14 | enum EEnum |
michael@0 | 15 | { |
michael@0 | 16 | kSimple, |
michael@0 | 17 | kPostMinus, |
michael@0 | 18 | kLimitedPostString, |
michael@0 | 19 | kUnLimitedPostString, |
michael@0 | 20 | kPostChar |
michael@0 | 21 | }; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | struct CSwitchForm |
michael@0 | 25 | { |
michael@0 | 26 | const wchar_t *IDString; |
michael@0 | 27 | NSwitchType::EEnum Type; |
michael@0 | 28 | bool Multi; |
michael@0 | 29 | int MinLen; |
michael@0 | 30 | int MaxLen; |
michael@0 | 31 | const wchar_t *PostCharSet; |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | struct CSwitchResult |
michael@0 | 35 | { |
michael@0 | 36 | bool ThereIs; |
michael@0 | 37 | bool WithMinus; |
michael@0 | 38 | UStringVector PostStrings; |
michael@0 | 39 | int PostCharIndex; |
michael@0 | 40 | CSwitchResult(): ThereIs(false) {}; |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | class CParser |
michael@0 | 44 | { |
michael@0 | 45 | int _numSwitches; |
michael@0 | 46 | CSwitchResult *_switches; |
michael@0 | 47 | bool ParseString(const UString &s, const CSwitchForm *switchForms); |
michael@0 | 48 | public: |
michael@0 | 49 | UStringVector NonSwitchStrings; |
michael@0 | 50 | CParser(int numSwitches); |
michael@0 | 51 | ~CParser(); |
michael@0 | 52 | void ParseStrings(const CSwitchForm *switchForms, |
michael@0 | 53 | const UStringVector &commandStrings); |
michael@0 | 54 | const CSwitchResult& operator[](size_t index) const; |
michael@0 | 55 | }; |
michael@0 | 56 | |
michael@0 | 57 | ///////////////////////////////// |
michael@0 | 58 | // Command parsing procedures |
michael@0 | 59 | |
michael@0 | 60 | struct CCommandForm |
michael@0 | 61 | { |
michael@0 | 62 | wchar_t *IDString; |
michael@0 | 63 | bool PostStringMode; |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | // Returns: Index of form and postString; -1, if there is no match |
michael@0 | 67 | int ParseCommand(int numCommandForms, const CCommandForm *commandForms, |
michael@0 | 68 | const UString &commandString, UString &postString); |
michael@0 | 69 | |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | #endif |