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

<p>The special characters and their entities for HTML are:</p>

<ul>
	<li><strong>Quotation Mark:</strong> the entity is <code>&amp;quot;</code> and symbol character is <code>&quot;</code>.</li>
	<li><strong>Single Quote Mark:</strong> the entity is <code>&amp;apos;</code> and symbol character is <code>&#39;</code>.</li>
	<li><strong>Ampersand:</strong> the entity is <code>&amp;amp;</code> and symbol character is <code>&amp;</code>.</li>
	<li><strong>Greater Than Sign:</strong> the entity is <code>&amp;gt;</code> and symbol character is <code>&gt;</code>.</li>
	<li><strong>Less Than Sign:</strong> the entity is <code>&amp;lt;</code> and symbol character is <code>&lt;</code>.</li>
	<li><strong>Slash:</strong> the entity is <code>&amp;frasl;</code> and symbol character is <code>/</code>.</li>
</ul>

<p>Given the input <code>text</code> string to the HTML parser, you have to implement the entity parser.</p>

<p>Return <em>the text after replacing the entities by the special characters</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> text = &quot;&amp;amp; is an HTML entity but &amp;ambassador; is not.&quot;
<strong>Output:</strong> &quot;&amp; is an HTML entity but &amp;ambassador; is not.&quot;
<strong>Explanation:</strong> The parser will replace the &amp;amp; entity by &amp;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> text = &quot;and I quote: &amp;quot;...&amp;quot;&quot;
<strong>Output:</strong> &quot;and I quote: \&quot;...\&quot;&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= text.length &lt;= 10<sup>5</sup></code></li>
	<li>The string may contain any possible characters out of all the 256 ASCII characters.</li>
</ul>

"""
1410. HTML Entity Parser

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 &quot; and symbol character is ".
- Single Quote Mark: the entity is &apos; and symbol character is '.
- Ampersand: the entity is &amp; and symbol character is &.
- Greater Than Sign: the entity is &gt; and symbol character is >.
- Less Than Sign: the entity is &lt; and symbol character is <.
- Slash: the entity is &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.
"""
from typing import List, Dict


class Solution:
    def entityParser(self, text: str) -> str:
        buf: List[str] = []
        buf0: List[str] = []

        map: Dict[str, str] = {"&quot;": "\"",
                               "&apos;": "'",
                               "&gt;": ">",
                               "&lt;": "<",
                               "&amp;": "&",
                               "&frasl;": "/"}

        curr = 0
        while curr < len(text):
            ch = text[curr]
            if ch == "&":
                buf0.append("&")
                curr += 1
                while curr < len(text) and text[curr] != "&" and text[curr] != ";":
                    buf0.append(text[curr])
                    curr += 1
                if curr == len(text) or text[curr] == "&":
                    buf.extend(buf0)
                    buf0.clear()
                    continue
                else:
                    buf0.append(text[curr])
                    s = "".join(buf0)
                    if s in map:
                        buf.append(map[s])
                    else:
                        buf.append(s)
                    buf0.clear()
            else:
                buf.append(ch)
            curr += 1

        return "".join(buf)
202