Skip to content

Commit

Permalink
Add utility method to Base32 to validate chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Mw3y committed May 24, 2024
1 parent c695baa commit 1c5531a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/ch/epfl/chacun/Base32.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ public class Base32 {
* @return true if and only if the string is valid and false otherwise
*/
public static boolean isValid(String string) {
return string.chars().allMatch(c -> ALPHABET.indexOf(c) != -1);
return string.chars().allMatch(c -> isValid((char) c));
}

/**
* Checks if the given character is valid in base 32.
*
* @param character the character to be checked
* @return true if and only if the character is valid and false otherwise
*/
public static boolean isValid(char character) {
return ALPHABET.indexOf(character) != -1;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ch/epfl/chacun/gui/ActionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static Node create(ObservableValue<List<String>> actionsO, Consumer<Strin
private static String sanitizeInput(String input) {
StringBuilder sanitizedInput = new StringBuilder();
for (char character : input.toUpperCase().toCharArray()) {
if (Base32.ALPHABET.indexOf(character) != -1)
if (Base32.isValid(character))
sanitizedInput.append(character);
}
return sanitizedInput.toString();
Expand Down

0 comments on commit 1c5531a

Please sign in to comment.