Open ChinSekYi opened 1 week ago
Accepted! We can find a way to make it insensitive :D
If you want to make prefix case-insensitive, then modify this code (i think): public class ArgumentTokenizer {
/**
* Tokenizes an arguments string and returns an {@code ArgumentMultimap} object that maps prefixes to their
* respective argument values. Only the given prefixes will be recognized in the arguments string.
*
* @param argsString Arguments string of the form: {@code preamble <prefix>value <prefix>value ...}
* @param prefixes Prefixes to tokenize the arguments string with
* @return ArgumentMultimap object that maps prefixes to their arguments
*/
public static ArgumentMultimap tokenize(String argsString, Prefix... prefixes) {
List<PrefixPosition> positions = findAllPrefixPositions(argsString, prefixes);
return extractArguments(argsString, positions);
}
/**
* Finds all zero-based prefix positions in the given arguments string.
*
* @param argsString Arguments string of the form: {@code preamble <prefix>value <prefix>value ...}
* @param prefixes Prefixes to find in the arguments string
* @return List of zero-based prefix positions in the given arguments string
*/
private static List<PrefixPosition> findAllPrefixPositions(String argsString, Prefix... prefixes) {
return Arrays.stream(prefixes)
.flatMap(prefix -> findPrefixPositions(argsString, prefix).stream())
.collect(Collectors.toList());
}
/**
* {@see findAllPrefixPositions}
*/
private static List<PrefixPosition> findPrefixPositions(String argsString, Prefix prefix) {
List<PrefixPosition> positions = new ArrayList<>();
int prefixPosition = findPrefixPosition(argsString, prefix.getPrefix(), 0);
while (prefixPosition != -1) {
//loop continuously calls for findPrefixPosition until it is not found
PrefixPosition extendedPrefix = new PrefixPosition(prefix, prefixPosition);
positions.add(extendedPrefix);
prefixPosition = findPrefixPosition(argsString, prefix.getPrefix(), prefixPosition);
}
return positions;
}
for command word: switch (commandWord)
Since the command meanings are exactly the same, command input should be case insensitive.
Example: Add vs ADD exit vs EXIT
In the above image, users will be confused as to why command is unknown. Maybe a better output message in the feedback box can be shown.