-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathInputParser.java
More file actions
35 lines (33 loc) · 1.65 KB
/
InputParser.java
File metadata and controls
35 lines (33 loc) · 1.65 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
34
35
public class InputParser {
static Object[] parseInput(String input) {
InputType type = InputType.NONE;
String[] value = new String[]{ input };
for(InputType inputType: InputType.values()) {
if (inputType == InputType.NONE) {
continue;
}
if (input.startsWith(inputType.label)) {
if (inputType == InputType.BYE || inputType == InputType.LIST) {
value = new String[]{};
} else if (inputType == InputType.TODO || inputType == InputType.MARK
|| inputType == InputType.UNMARK) {
String description = input.substring(inputType.label.length() + 1);
value = new String[]{description};
} else if (inputType == InputType.DEADLINE) {
int datetimeIndex = input.indexOf("/by");
String description = input.substring(inputType.label.length() + 1, datetimeIndex - 1);
String datetime = input.substring(datetimeIndex + 4);
value = new String[]{description, datetime};
} else if (inputType == InputType.EVENT) {
int datetimeIndex = input.indexOf("/at");
String description = input.substring(inputType.label.length() + 1, datetimeIndex - 1);
String datetime = input.substring(datetimeIndex + 4);
value = new String[]{description, datetime};
}
type = inputType;
return new Object[]{type, value};
}
}
return new Object[]{type, value};
}
}