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