-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandParser.cpp
More file actions
33 lines (31 loc) · 1.04 KB
/
CommandParser.cpp
File metadata and controls
33 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Author(s): Yuval Anteby
#include "./CommandParser.h"
#include "./bloom/commands/utils/CommandRequest.h"
#include "bloom/utils/command_code/BloomCommandCodeParser.h"
#include "strategy_io/utils/InputValidation.h"
#include <sstream>
#include <string>
/**
* Turns a line of input to a command request object.
* @param line line of input from the user
* @return command request object made of {string command, string url}
*/
CommandRequest CommandParser::parseCommand(const std::string& line) {
// If input is empty then it's invalid
if(line.empty()) {
std::string emptyString = "";
return CommandRequest{emptyString, emptyString};
}
std::istringstream iss(line);
std::string command;
std::string url;
iss >> command >> url;
BloomFilterCommandEnum cmdCode = toCommandCode(command);
// check validation of the URL
if(!isValidURL(url) || cmdCode == CMD_NONE) {
std::string emptyString = "";
return CommandRequest{emptyString, emptyString};
}
// Valid input, create the request object
return CommandRequest{command, url};
}