Home | History | Annotate | Download | only in Common
      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   enum EEnum
     15   {
     16     kSimple,
     17     kPostMinus,
     18     kLimitedPostString,
     19     kUnLimitedPostString,
     20     kPostChar
     21   };
     22 }
     23 
     24 struct CSwitchForm
     25 {
     26   const wchar_t *IDString;
     27   NSwitchType::EEnum Type;
     28   bool Multi;
     29   int MinLen;
     30   int MaxLen;
     31   const wchar_t *PostCharSet;
     32 };
     33 
     34 struct CSwitchResult
     35 {
     36   bool ThereIs;
     37   bool WithMinus;
     38   UStringVector PostStrings;
     39   int PostCharIndex;
     40   CSwitchResult(): ThereIs(false) {};
     41 };
     42 
     43 class CParser
     44 {
     45   int _numSwitches;
     46   CSwitchResult *_switches;
     47   bool ParseString(const UString &s, const CSwitchForm *switchForms);
     48 public:
     49   UStringVector NonSwitchStrings;
     50   CParser(int numSwitches);
     51   ~CParser();
     52   void ParseStrings(const CSwitchForm *switchForms,
     53     const UStringVector &commandStrings);
     54   const CSwitchResult& operator[](size_t index) const;
     55 };
     56 
     57 /////////////////////////////////
     58 // Command parsing procedures
     59 
     60 struct CCommandForm
     61 {
     62   const wchar_t *IDString;
     63   bool PostStringMode;
     64 };
     65 
     66 // Returns: Index of form and postString; -1, if there is no match
     67 int ParseCommand(int numCommandForms, const CCommandForm *commandForms,
     68     const UString &commandString, UString &postString);
     69 
     70 }
     71 
     72 #endif
     73