-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1410-HTML enitity parser.cpp
38 lines (38 loc) · 1.14 KB
/
1410-HTML enitity parser.cpp
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
30
31
32
33
34
35
36
37
38
class Solution {
public:
string entityParser(string s) {
string k="";
for (int i=0;i<s.length();i++){
if (s[i]=='&'){
if (i+4<=s.length() && s.substr(i+1,4)==("amp;")){
k+='&';
i+=4;
}
else if (i+5<=s.length() && s.substr(i+1,5)==("quot;")){
k.append("\"");
i+=5;
}
else if (i+5 <=s.length() && s.substr(i+1,5)==("apos;")){
k+="'";
i+=5;
}
else if (i+3<=s.length() && s.substr(i+1,3)==("gt;")){
k+='>';i+=3;
}
else if (i+3 <= s.length() && s.substr(i+1,3)==("lt;")){
k+='<';i+=3;
}
else if (i+6<=s.length() && s.substr(i+1,6)==("frasl;")){
k+="/";i+=6;
}
else{
k+=s[i];
}
}
else{
k+=s[i];
}
}
return k;
}
};