Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / html / entity.go
blobe9f27b9041c2d89f7cdee7cb11070525c959e01d
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.
5 package html
7 import (
8 "utf8"
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',
22 "amp;": '\U00000026',
23 "apos;": '\U00000027',
24 "gt;": '\U0000003E',
25 "lt;": '\U0000003C',
26 "quot;": '\U00000022',
29 func init() {
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))