-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlValidator.java
More file actions
27 lines (24 loc) · 845 Bytes
/
Copy pathHtmlValidator.java
File metadata and controls
27 lines (24 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.List;
import java.util.Stack;
public class HtmlValidator {
/**
* verifica se o código Html é malformado
* @param lines Linhas do Html
* @return true se o html for malformado, false do contrário
*/
public boolean isMalformedHtml(List<String> lines) {
Stack<String> tags = new Stack<>();
for (String line : lines) {
if (HtmlUtils.isOpeningTag(line)) {
String tagName = line.substring(1, line.length() - 1);
tags.push(tagName);
} else if (HtmlUtils.isClosingTag(line)) {
String tagName = line.substring(2, line.length() - 1);
if (tags.isEmpty() || !tags.pop().equals(tagName)) {
return true;
}
}
}
return !tags.isEmpty();
}
}