4 Command::Command(const char* commandLine
) :
20 int Command::Parse(const char* commandLine
, const char* delimiters
)
22 // clear any parameters that may already be in the command
25 // allocate and store off a local version of the command line string
26 int commandLineLength
= static_cast<int>(strlen(commandLine
));
27 _tokens
= new char[commandLineLength
+ 1];
28 strcpy_s(_tokens
, commandLineLength
+ 1, commandLine
);
30 // parse out the individual parameters in the command line string
32 char* token
= strtok_s(_tokens
, delimiters
, &locale
);
35 _parameters
.push_back(token
);
36 token
= strtok_s(0, delimiters
, &locale
);
39 return GetParameterCount();
53 char* Command::GetParameter(int index
, char* parameter
, int size
) const
55 if (index
< GetParameterCount())
57 strcpy_s(parameter
, size
, _parameters
[index
]);
67 const char* Command::GetParameter(int index
) const
69 if (index
< GetParameterCount())
71 return _parameters
[index
];
77 int Command::GetParameterCount() const
79 return static_cast<int>(_parameters
.size());
82 int Command::FindParameter(const char* parameter
, bool caseSensitive
) const
84 for (int i
= 0; i
< GetParameterCount(); i
++)
88 if (strcmp(parameter
, GetParameter(i
)) == 0)
96 if (_stricmp(parameter
, GetParameter(i
)) == 0)
106 bool Command::HasParameter(const char* parameter
, bool caseSensitive
) const
108 return FindParameter(parameter
, caseSensitive
) > -1;