HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.

The special characters and their entities for HTML are:


	Quotation Mark: the entity is &amp;quot; and symbol character is ".
	Single Quote Mark: the entity is &amp;apos; and symbol character is '.
	Ampersand: the entity is &amp;amp; and symbol character is &amp;.
	Greater Than Sign: the entity is &amp;gt; and symbol character is &gt;.
	Less Than Sign: the entity is &amp;lt; and symbol character is &lt;.
	Slash: the entity is &amp;frasl; and symbol character is /.


Given the input text string to the HTML parser, you have to implement the entity parser.

Return the text after replacing the entities by the special characters.

&nbsp;
Example 1:

Input: text = "&amp;amp; is an HTML entity but &amp;ambassador; is not."
Output: "&amp; is an HTML entity but &amp;ambassador; is not."
Explanation: The parser will replace the &amp;amp; entity by &amp;


Example 2:

Input: text = "and I quote: &amp;quot;...&amp;quot;"
Output: "and I quote: \"...\""


&nbsp;
Constraints:


	1 &lt;= text.length &lt;= 105
	The string may contain any possible characters out of all the 256 ASCII characters.


class Solution:
    def entityParser(self, text: str) -> str:
        d = {"&quot;" : '"' , "&apos;":"'" , "&amp;" : "&" , "&gt;" : ">" , "&lt;":"<" , "&frasl;" : "/"}
        
        
        
        ans = ""
        i = 0
        while i < len(text):
            bag = ""
            
            #condition if find & and next char is not & also and handdling index out of range for i + 1
            if i+1 < len(text) and text[i] == "&" and text[i+1] != "&":
                
                #create subtring for speacial char till ";"
                for j in range(i , len(text)):
                    if text[j] == ";":
                        bag += text[j]
                        break
                    else:
                        bag += text[j]
                        
                #if that not present in dict we added same as it is
                if bag not in d:
                    ans += bag
                else:
                    ans += d[bag]
                    
                #increment by length of bag 
                i += len(bag)
             
            #otherwise increment by 1
            else:
                ans += text[i]
                i += 1
        return ans
        
class Solution {
    public String entityParser(String text) {
        return text.replace("&quot;","\"").replace("&apos;","'").replace("&gt;",">").replace("&lt;","<").replace("&frasl;","/").replace("&amp;","&");
    }
}
class Solution {
public:
    string entityParser(string text) {
        map<string,char>mp;
        mp["&quot;"] = '\"';
        mp["&apos;"] = '\'';
        mp["&amp;"] = '&';
        mp["&gt;"] = '>';mp["&lt;"]='<';
        mp["&frasl;"] = '/';
        
        for(int i =0;i<text.size();i++){
            if(text[i]=='&'){
                int j = i;
                string com ="";
                while(text[j]!=';' && j<text.size()){
                    com+=text[j];
                    j++;
                }
                com+=text[j];
                if(mp.find(com)!=mp.end()){
                    text.erase(i,j-i);
                    text[i] = mp[com];
                }
                
            }
        }
        return text;
    }
};
/**
 * @param {string} text
 * @return {string}
 */
var entityParser = function(text) {
    const entityMap = {
        '&quot;': `"`,
        '&apos;': `'`,
        '&amp;': `&`,
        '&gt;': `>`,
        '&lt;': `<`,
        '&frasl;': `/`
    }
    
    stack = [], entity = "";
    
    for(const char of text) {
        stack.push(char);
        if(char == '&') {
            if(entity.length > 0) entity = "";
            entity += char;
        }
        else if(char == ';' && entity.length > 0) {
            entity += char;
            
            if(entity in entityMap) {
                while(stack.length && stack[stack.length - 1] !== '&') {
                    stack.pop();
                }
                stack.pop();
                stack.push(entityMap[entity]);
            }
            
            entity = "";
        }
        else if(entity.length > 0) {
            entity += char;
        }
    }
    
    return stack.join('');
};
HTML Entity Parser