Skip to content

Commit a4faf9e

Browse files
committed
removing spaces between arguments
1 parent 8ecb810 commit a4faf9e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/echo_command.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "echo_command.h"
22
#include <iostream>
33

4+
45
void EchoCommand::execute(const std::string& args) {
6+
57
std::cout << args << std::endl;
68
}
79

src/shell.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <iostream>
33
#include <sstream>
44
#include <unistd.h>
5+
#include <vector>
56

67
void 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)) {

0 commit comments

Comments
 (0)