CommandLineParser.h 1.4 KB

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