1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 // entity is a map from HTML entity names to their values. The semicolon matters:
12 // http://www.whatwg.org/specs/web-apps/current-work/multipage/named-character-references.html
13 // lists both "amp" and "amp;" as two separate entries.
15 // TODO(nigeltao): Take the complete map from the HTML5 spec section 10.5 "Named character references".
16 // http://www.whatwg.org/specs/web-apps/current-work/multipage/named-character-references.html
17 // Note that the HTML5 list is larger than the HTML4 list at
18 // http://www.w3.org/TR/html4/sgml/entities.html
19 var entity
= map[string]int{
20 "aacute": '\U000000E1',
21 "aacute;": '\U000000E1',
23 "apos;": '\U00000027',
26 "quot;": '\U00000022',
30 // We verify that the length of UTF-8 encoding of each value is <= 1 + len(key).
31 // The +1 comes from the leading "&". This property implies that the length of
32 // unescaped text is <= the length of escaped text.
33 for k
, v
:= range entity
{
34 if 1+len(k
) < utf8
.RuneLen(v
) {
35 panic("escaped entity &" + k
+ " is shorter than its UTF-8 encoding " + string(v
))