-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTML 实体解析器 [html-entity-parser].html
61 lines (44 loc) · 2.58 KB
/
HTML 实体解析器 [html-entity-parser].html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<p>「HTML 实体解析器」 是一种特殊的解析器,它将 HTML 代码作为输入,并用字符本身替换掉所有这些特殊的字符实体。</p>
<p>HTML 里这些特殊字符和它们对应的字符实体包括:</p>
<ul>
<li><strong>双引号:</strong>字符实体为 <code>&quot;</code> ,对应的字符是 <code>"</code> 。</li>
<li><strong>单引号:</strong>字符实体为 <code>&apos;</code> ,对应的字符是 <code>'</code> 。</li>
<li><strong>与符号:</strong>字符实体为 <code>&amp;</code> ,对应对的字符是 <code>&</code> 。</li>
<li><strong>大于号:</strong>字符实体为 <code>&gt;</code> ,对应的字符是 <code>></code> 。</li>
<li><strong>小于号:</strong>字符实体为 <code>&lt;</code> ,对应的字符是 <code><</code> 。</li>
<li><strong>斜线号:</strong>字符实体为 <code>&frasl;</code> ,对应的字符是 <code>/</code> 。</li>
</ul>
<p>给你输入字符串 <code>text</code> ,请你实现一个 HTML 实体解析器,返回解析器解析后的结果。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>text = "&amp; is an HTML entity but &ambassador; is not."
<strong>输出:</strong>"& is an HTML entity but &ambassador; is not."
<strong>解释:</strong>解析器把字符实体 &amp; 用 & 替换
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>text = "and I quote: &quot;...&quot;"
<strong>输出:</strong>"and I quote: \"...\""
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>text = "Stay home! Practice on Leetcode :)"
<strong>输出:</strong>"Stay home! Practice on Leetcode :)"
</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入:</strong>text = "x &gt; y &amp;&amp; x &lt; y is always false"
<strong>输出:</strong>"x > y && x < y is always false"
</pre>
<p><strong>示例 5:</strong></p>
<pre>
<strong>输入:</strong>text = "leetcode.com&frasl;problemset&frasl;all"
<strong>输出:</strong>"leetcode.com/problemset/all"
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= text.length <= 10^5</code></li>
<li>字符串可能包含 256 个ASCII 字符中的任意字符。</li>
</ul>