Fixed String encoding

This commit is contained in:
Marc Beyer 2022-01-11 17:14:30 +01:00
parent ea6420e234
commit 0ef383aa7f
2 changed files with 30 additions and 4 deletions

View File

@ -164,7 +164,7 @@ public class MainController {
vBox.getChildren().add(timeLabel);
}
Label typeLabel = new Label("Wer: " + event.getOwnerName());
Label typeLabel = new Label("Wer: " + event.getOwnerName().replace("ü", "\u00fc"));
vBox.getChildren().add(typeLabel);
/*

View File

@ -2,6 +2,7 @@ package res;
import com.sun.jdi.event.StepEvent;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -70,10 +71,30 @@ public class Event {
if(name.length() < 3){
throw new IllegalArgumentException("Der Name muss eine L\u00e4nge von 3 haben.");
}
Pattern pattern = Pattern.compile("[A-Za-zÄÖÜäöü0-9 =!?+*/$%€.:,;_<>()-]*");
Pattern pattern = Pattern.compile("[A-Za-z\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df0-9 =!?+*/$%.:,;_<>()-]*");
Matcher matcher = pattern.matcher(name);
if(!matcher.matches()){
throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: =!?+*/$%€.:,;_ <>()-");
System.out.println(name);
byte[] bytes = name.getBytes(StandardCharsets.UTF_16);
String utf8EncodedString = new String(bytes, StandardCharsets.UTF_16);
System.out.println(utf8EncodedString);
for (char c : (name).toCharArray()) {
System.out.print(c + " " + (int)c + ", ");
}
System.out.println();
for (char c : (name).toCharArray()) {
System.out.print(c + " " + (int)c + ", ");
}
System.out.println();
for (char c : ("TäöüÄÖÜ").toCharArray()) {
System.out.print(c + " " + (int)c + ", ");
}
System.out.println();
throw new IllegalArgumentException("Der Name darf nur aus Zahlen, Buchstaben und folgenden Sonderzeichen bestehen: \u00e4\u00f6\u00fc \u00c4\u00d6\u00dc \u00df =!?+*/$%.:,;_ <>()-");
}
if(priority < 0){
throw new IllegalArgumentException("Bitte eine Priorit\u00e4t w\u00e4hlen.");
@ -106,7 +127,7 @@ public class Event {
}
public void setName(String name) {
this.name = name;
this.name = convertToASCII(name);
}
public int getPriority() {
@ -192,4 +213,9 @@ public class Event {
"&isFullDay=" + isFullDay() +
"&isPrivate=" + isPrivate();
}
private String convertToASCII(String s){
byte[] germanBytes = s.getBytes();
return new String(germanBytes, StandardCharsets.US_ASCII);
}
}