AY2425S1-CS2103-F09-3 / tp

MIT License
0 stars 4 forks source link

[General] Should command be case insensitive? #174

Open ChinSekYi opened 1 week ago

ChinSekYi commented 1 week ago

Since the command meanings are exactly the same, command input should be case insensitive.

Example: Add vs ADD exit vs EXIT

Screenshot 2024-10-27 at 6 42 08 PM

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.

hazzle23 commented 3 days ago

Accepted! We can find a way to make it insensitive :D

vicelyav commented 3 days ago

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;
}
vicelyav commented 3 days ago

for command word: switch (commandWord)