1 // Common/CommandLineParser.h
2 
3 #ifndef __COMMON_COMMAND_LINE_PARSER_H
4 #define __COMMON_COMMAND_LINE_PARSER_H
5 
6 #include "MyString.h"
7 
8 namespace NCommandLineParser {
9 
10 bool SplitCommandLine(const UString &src, UString &dest1, UString &dest2);
11 void SplitCommandLine(const UString &s, UStringVector &parts);
12 
13 namespace NSwitchType
14 {
15   enum EEnum
16   {
17     kSimple,
18     kMinus,
19     kString,
20     kChar
21   };
22 }
23 
24 struct CSwitchForm
25 {
26   const char *Key;
27   Byte Type;
28   bool Multi;
29   Byte MinLen;
30   // int MaxLen;
31   const char *PostCharSet;
32 };
33 
34 struct CSwitchResult
35 {
36   bool ThereIs;
37   bool WithMinus;
38   int PostCharIndex;
39   UStringVector PostStrings;
40 
CSwitchResultCSwitchResult41   CSwitchResult(): ThereIs(false) {};
42 };
43 
44 class CParser
45 {
46   CSwitchResult *_switches;
47 
48   bool ParseString(const UString &s, const CSwitchForm *switchForms, unsigned numSwitches);
49 public:
50   UStringVector NonSwitchStrings;
51   int StopSwitchIndex;  // NonSwitchStrings[StopSwitchIndex+] are after "--"
52   AString ErrorMessage;
53   UString ErrorLine;
54 
55   CParser();
56   ~CParser();
57   bool ParseStrings(const CSwitchForm *switchForms, unsigned numSwitches, const UStringVector &commandStrings);
58   const CSwitchResult& operator[](unsigned index) const { return _switches[index]; }
59 };
60 
61 }
62 
63 #endif
64