This commit is contained in:
1 parent
9d6b945f82
commit
0042f539a5
44 files changed
+1380
-511
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package games.dmg.fantasystick.party;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Validated display and globally comparable identities for persistent parties. */
|
||||
public final class PartyNames {
|
||||
public record Name(String display, String canonical) { }
|
||||
|
||||
private PartyNames() { }
|
||||
|
||||
public static Optional<Name> parse(String input) {
|
||||
if (input == null) return Optional.empty();
|
||||
String display = Normalizer.normalize(input.strip(), Normalizer.Form.NFC);
|
||||
int length = display.codePointCount(0, display.length());
|
||||
if (length < 1 || length > 32 || display.codePoints().anyMatch(PartyNames::forbidden)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String canonical = Normalizer.normalize(display.toLowerCase(Locale.ROOT), Normalizer.Form.NFC);
|
||||
return Optional.of(new Name(display, canonical));
|
||||
}
|
||||
|
||||
private static boolean forbidden(int codePoint) {
|
||||
int type = Character.getType(codePoint);
|
||||
return type == Character.CONTROL || type == Character.FORMAT || type == Character.SURROGATE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user