Question: #include #include std::vector parseCommandLine ( const std::string& aCommandLine ) { std::cout < < in 2 < < std::endl; std::vector tokens; size _ t
#include
#include
std::vector parseCommandLineconst std::string& aCommandLine
std::cout in std::endl;
std::vector tokens;
sizet start ;
while start aCommandLine.size
sizet end start;
while end aCommandLine.size &&
aCommandLineend &&
aCommandLineend &&
aCommandLineend &&
aCommandLineend
end;
std::string token aCommandLine.substrstart end start;
Handle file redirection with and
if token.empty && tokenback token.back
tokens.pushbacktokensubstr token.size;
tokens.pushbackstd::string token.back;
Handle file redirection with
else if token && start
tokens.pushbacktoken;
Handle pipe
else if token
tokens.pushbacktoken;
Handle other tokens
else if token.empty
tokens.pushbacktoken;
Move to the next nonwhitespace character
while end aCommandLine.size && aCommandLineend
end;
start end;
std::cout finished" std::endl;
return tokens;
int main
std::cout in std::endl;
std::string commandLine "grep x myfile.textbfin myfile.out";
std::cout ut std::endl;
std::vector result parseCommandLinecommandLine;
std::cout ut std::endl;
Print the parsed tokens
for sizet i ; i result.size; i
std::cout "Token i : resulti std::endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
