package com.marcelherd.uebung6;

import static gdi.MakeItSimple.*;

public class StringExtensions {

	public static void main(String[] args) {
		println("aeiouäüöfjdsü903953h0ßfsaÄÜÜÖÜDÜPK\n" + toUpper("aeiouäüöfjdsü903953h0ßfsaÄÜÜÖÜDÜPK"));
		String[] s = split("", ';');
		for(String k : s){
			println(k);
		}
		println(scan("asdasdsa", "asdasdsa") + "");
	}

	public static String toUpper(String original) {
		String upperOriginal = "";
		for (int i = 0; i < original.length(); i++) {
			char currentCharacter = original.charAt(i);
			if (currentCharacter >= 'a' && currentCharacter <= 'z') {
				upperOriginal += (char) (currentCharacter - 'a' + 'A');
			} else if (currentCharacter == 'ä') {
				upperOriginal += 'Ä';
			} else if (currentCharacter == 'ö') {
				upperOriginal += 'Ö';
			} else if (currentCharacter == 'ü') {
				upperOriginal += 'Ü';
			} else {
				upperOriginal += currentCharacter;
			}
		}
		return upperOriginal;
	}
	
	
	public static String[] split(String original, char delimiter){
		int numberOfParts = 1;
		for(int i = 0; i<original.length(); i++){
			if(original.charAt(i)==delimiter){
				numberOfParts++;
			}
		}
		String[] splittedStringArray = new String[numberOfParts];
		int currentPart = 0;
		splittedStringArray[0] = "";
		for(int i = 0; i<original.length(); i++){
			if(original.charAt(i)!=delimiter){
				splittedStringArray[currentPart]+=original.charAt(i);
			}else{
				currentPart++;
				splittedStringArray[currentPart] = "";
			}
		}
		return splittedStringArray;
	}
	
	public static int scan(String original, String needle){
		if(needle.length()>original.length()){
			throw new GDIException("Die eingegebene Zeichenkette ist länger als die zu durchsuchende Zeichenkette!");
		}
		if(needle.length()==0){
			throw new GDIException("Der zu suchende String darf nicht leer sein!");
		}
		if(original.length()==0){
			throw new GDIException("Der zu durchsuchende String darf nicht leer sein!");
		}
		int needleLength = needle.length();
		boolean needleFound = false;
		int needlePosition = -1;
		for(int i = 0; i<original.length()-needle.length()+1 && !needleFound; i++){
			String actualCheck = "";
			for(int j = i; j<needleLength+i && !needleFound; j++){
				actualCheck+=original.charAt(j);
			}
			if(actualCheck.equals(needle)){
				needleFound = true;
				needlePosition = i;
			}
		}
		return needlePosition;
		
		
	}
}

@@ -181,16 +181,17 @@
 %C3%9C%C3%9C%C3%96%C3%9CD%C3%9CPK
+.
 %5Cn%22 + to
@@ -231,16 +231,17 @@
 %C3%9C%C3%9C%C3%96%C3%9CD%C3%9CPK
+.
 %22));%0A%09%09S
@@ -416,27 +416,20 @@
 %09String 
-upperOrigin
+retv
 al = %22%22;
@@ -425,24 +425,27 @@
 etval = %22%22;%0A
+%09%09%0A
 %09%09for (int i
@@ -489,31 +489,16 @@
 %09%09char c
-urrentCharacter
  = origi
@@ -524,50 +524,20 @@
 f (c
-urrentCharacter %3E= 'a' && currentCharacter
+ %3E= 'a' && c
  %3C= 
@@ -543,35 +543,28 @@
  'z') %7B%0A%09%09%09%09
-upperOrigin
+retv
 al += (char)
@@ -566,31 +566,16 @@
 char) (c
-urrentCharacter
  - 'a' +
@@ -600,243 +600,224 @@
 f (c
-urrentCharacter == '%C3%A4') %7B%0A%09%09%09%09upperOriginal += '%C3%84';%0A%09%09%09%7D else if (currentCharacter == '%C3%B6') %7B%0A%09%09%09%09upperOriginal += '%C3%96';%0A%09%09%09%7D else if (currentCharacter == '%C3%BC') %7B%0A%09%09%09%09upperOriginal += '%C3%9C';%0A%09%09%09%7D else %7B%0A%09%09%09%09upperOriginal += currentCharacter
+ == '%C3%A4' %7C%7C c== '%C3%BC' %7C%7C c== '%C3%B6') %7B%0A%09%09%09%09/* Die Minuskel der Umlaute sind genau 32 Stellen von ihren Majuskeln entfernt.%0A%09%09%09%09 * (char) 32 entspricht ' '%0A%09%09%09%09 */%0A%09%09%09%09retval += (char) (c - ' ');%0A%09%09%09%7D else %7B%0A%09%09%09%09retval += c
 ;%0A%09%09
@@ -815,32 +815,35 @@
  += c;%0A%09%09%09%7D%0A%09%09%7D%0A
+%09%09%0A
 %09%09return upperOr
@@ -839,19 +839,12 @@
 urn 
-upperOrigin
+retv
 al;%0A

Simplified toUpper