<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>

class Solution:
    def entityParser(self, text: str) -> str:
        # Dictionary to map entities to their corresponding special characters
        entity_map = {
            "&quot;": "\"",
            "&apos;": "'",
            "&amp;": "&",
            "&gt;": ">",
            "&lt;": "<",
            "&frasl;": "/"
        }

        # Initialize an empty list to store the parsed characters
        parsed_text = []

        # Initialize a variable to keep track of the start index of a potential entity
        start_index = 0

        # Iterate through the text
        while start_index < len(text):
            # Check if the current character is '&', which may indicate the start of an entity
            if text[start_index] == '&':
                # Find the end of the potential entity, which is marked by ';'
                end_index = text.find(';', start_index)

                # If ';' is found and the text in between '&' and ';' is a valid entity
                if end_index != -1 and text[start_index:end_index+1] in entity_map:
                    # Replace the entity with its corresponding special character
                    parsed_text.append(entity_map[text[start_index:end_index+1]])
                    # Move the start index to the position after the end of the entity
                    start_index = end_index + 1
                else:
                    # If it's not a valid entity, just append the '&' character
                    parsed_text.append(text[start_index])
                    start_index += 1
            else:
                # If the current character is not '&', just append it to the parsed text
                parsed_text.append(text[start_index])
                start_index += 1

        # Join the list of parsed characters into a single string
        return ''.join(parsed_text)

# Example usage:
solution = Solution()
print(solution.entityParser("&amp; is an HTML entity but &ambassador; is not."))  # Output: "& is an HTML entity but &ambassador; is not."
print(solution.entityParser("and I quote: &quot;...&quot;"))  # Output: "and I quote: \"...\""
153