-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandParser.java
More file actions
72 lines (60 loc) · 1.52 KB
/
Copy pathCommandParser.java
File metadata and controls
72 lines (60 loc) · 1.52 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*;
public class CommandParser {
private String command;
private Vector<String> arguments = new Vector<String>();
private int argument = 0;
public CommandParser(String cmd_string) {
StringTokenizer tokenizer = new StringTokenizer(cmd_string, " ");
this.command = tokenizer.nextToken();
Boolean informationrich = false;
String theToken = "";
while(tokenizer.hasMoreTokens()) {
String current = tokenizer.nextToken();
if ( ! informationrich && current.startsWith("\"")) {
informationrich = true;
current = current.substring(1);
theToken = current;
} else if ( informationrich) {
if(current.endsWith("\"")) {
informationrich = false;
current = current.substring(0, current.length() - 1);
}
theToken += " " + current;
} else {
theToken = current;
}
if( ! informationrich || ! tokenizer.hasMoreTokens()) {
arguments.add(theToken);
theToken = "";
}
}
}
public int count_arguments() {
return this.arguments.size();
}
public Boolean isEqual(String ... cmds) {
for (int i = 0; i < cmds.length; i++) {
if (command.equalsIgnoreCase(cmds [i])) {
return true;
}
}
return false;
}
public String next_argument() {
if (this.argument < this.arguments.size()) {
String current = this.arguments.get(argument);
argument++;
return current;
}
return "";
}
public Vector<String> get_arguments() {
return this.arguments;
}
public String get_command() {
return command;
}
public String toString() {
return command;
}
}