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