File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 11#include " echo_command.h"
22#include < iostream>
33
4+
45void EchoCommand::execute (const std::string& args) {
6+
57 std::cout << args << std::endl;
68}
79
Original file line number Diff line number Diff line change 22#include < iostream>
33#include < sstream>
44#include < unistd.h>
5+ #include < vector>
56
67void Shell::run () {
78 // Flush after every std::cout / std:cerr
@@ -22,12 +23,22 @@ void Shell::run() {
2223 // trim leading whitespace
2324 size_t start = args.find_first_not_of (" " );
2425 if (args.find_first_of (" '" ) != std::string::npos && args.find_first_of (" '" ) < args.find_last_of (" '" )) {
25- args = args.substr (args.find_first_of (" '" ), args.find_last_of (" '" )-1 );
26- }
27- if (start != std::string::npos) {
28- args = args.substr (start);
26+ args = args.substr (args.find_first_of (" '" ) + 1 , args.find_last_of (" '" )-2 );
2927 } else {
28+ std::istringstream argsStream (args);
29+ std::vector<std::string> argList;
30+ std::string arg;
31+ while (argsStream >> arg) {
32+ argList.push_back (arg);
33+ }
34+
3035 args.clear ();
36+ for (size_t i = 0 ; i < argList.size (); ++i) {
37+ args += argList[i];
38+ if (i < argList.size ()) {
39+ args += " " ;
40+ }
41+ }
3142 }
3243
3344 if (auto * command = commandFactory.get (cmd)) {
You can’t perform that action at this time.
0 commit comments