Fixed String encoding
This commit is contained in:
		@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user