Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string entityParser(string text) {
- unordered_map<string, char> m;
- m["""] = '"';
- m["'"] = '\'';
- m["&"] = '&';
- m[">"] = '>';
- m["<"] = '<';
- m["⁄"] = '/';
- string ans = "";
- int sz = text.length();
- for(int i=0; i<sz; i++){
- if(text[i] == '&'){
- string tmp = "&"; i++;
- while(i < sz){
- tmp += text[i];
- if(text[i] == ';' && m.find(tmp) != m.end()){
- ans += m[tmp];
- break;
- }
- if(text[i] == '&'){
- ans += tmp.substr(0, tmp.length()-1);
- i--;
- break;
- }
- i++;
- }
- if(i == sz) ans += tmp;
- }
- else{
- ans += text[i];
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement