Aufgabe 4 gelöst.

This commit is contained in:
schrom01 2022-09-20 21:51:29 +02:00
parent 49a8836144
commit 67c7b6e78a
2 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/*
package ch.zhaw.ads; package ch.zhaw.ads;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -34,4 +34,3 @@ public class ADS1_4_test {
} }
} }
*/

View File

@ -8,6 +8,43 @@ public class WellformedXmlServer implements CommandExecutor {
} }
public boolean checkWellformed(String arg) { public boolean checkWellformed(String arg) {
Stack stack = new ListStack();
char[] chars = arg.toCharArray();
for(int i = 0; i < chars.length; i++){
if(chars[i] == '<') {
boolean closing = false;
i++;
if(chars[i] == '/'){
closing = true;
i++;
}
String tag = "";
while(chars[i] != '>' && chars[i] != ' '){
tag = tag + chars[i];
i++;
}
if(tag.charAt(tag.length() - 1) == '/') {
} }
else if (closing){
if(!tag.equals(stack.pop())){
return false;
}
} else {
stack.push(tag);
}
}
}
if(stack.isEmpty()){
return true;
} else {
return false;
}
}
private String getNextToken(){
return null;
}
} }