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