other-licenses/7zstub/src/Common/CommandLineParser.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 // Common/CommandLineParser.h
     3 #ifndef __COMMON_COMMANDLINEPARSER_H
     4 #define __COMMON_COMMANDLINEPARSER_H
     6 #include "Common/String.h"
     8 namespace NCommandLineParser {
    10 void SplitCommandLine(const UString &src, UString &dest1, UString &dest2);
    11 void SplitCommandLine(const UString &s, UStringVector &parts);
    13 namespace NSwitchType {
    14   enum EEnum
    15   { 
    16     kSimple,
    17     kPostMinus,
    18     kLimitedPostString,
    19     kUnLimitedPostString,
    20     kPostChar
    21   };
    22 }
    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 };
    34 struct CSwitchResult
    35 {
    36   bool ThereIs;
    37   bool WithMinus;
    38   UStringVector PostStrings;
    39   int PostCharIndex;
    40   CSwitchResult(): ThereIs(false) {};
    41 };
    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 };
    57 /////////////////////////////////
    58 // Command parsing procedures
    60 struct CCommandForm
    61 {
    62   wchar_t *IDString;
    63   bool PostStringMode;
    64 };
    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);
    70 }
    72 #endif

mercurial