-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy path1410.java
29 lines (27 loc) · 965 Bytes
/
1410.java
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
28
29
class Solution {
public String entityParser(String text) {
Map<String, String> entity = new HashMap();
entity.put("&", "&");
entity.put(""", "\"");
entity.put("&apos", "'");
entity.put(">", ">");
entity.put("<", "<");
entity.put("&frasl", "/");
StringBuilder res = new StringBuilder();
int n = text.length(), i = 0;
while (i < n) {
if (text.charAt(i) == '&') {
StringBuilder t = new StringBuilder();
while (text.charAt(i) != ';') {
t.append(text.charAt(i));
i++;
}
String cur = t.toString();
if (entity.containsKey(cur)) res.append(entity.get(cur));
else res.append(cur).append(";");
} else res.append(text.charAt(i));
i++;
}
return res.toString();
}
}