1 // Copyright 2013 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.
13 // Elem is implemented by every XML element.
23 CharData string `xml:",chardata"`
26 Source string `xml:"source,attr"`
27 Path string `xml:"path,attr"`
31 Choice string `xml:"choice,attr,omitempty"`
32 Type string `xml:"type,attr,omitempty"`
36 // Common holds several of the most common attributes and sub elements
42 Type string `xml:"type,attr,omitempty"`
43 Reference string `xml:"reference,attr,omitempty"`
44 Alt string `xml:"alt,attr,omitempty"`
45 ValidSubLocales string `xml:"validSubLocales,attr,omitempty"`
46 Draft string `xml:"draft,attr,omitempty"`
50 // Default returns the default type to select from the enclosed list
51 // or "" if no default value is specified.
52 func (e *Common) Default() string {
56 if e.Def.Choice != "" {
58 } else if e.Def.Type != "" {
59 // Type is still used by the default element in collation.
65 // GetCommon returns e. It is provided such that Common implements Elem.
66 func (e *Common) GetCommon() *Common {
70 // Data returns the character data accumulated for this element.
71 func (e *Common) Data() string {
72 e.CharData = charRe.ReplaceAllStringFunc(e.CharData, replaceUnicode)
76 func (e *Common) setName(s string) {
80 func (e *Common) enclosing() Elem {
84 func (e *Common) setEnclosing(en Elem) {
88 // Escape characters that can be escaped without further escaping the string.
89 var charRe = regexp.MustCompile(`&#x[0-9a-fA-F]*;|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\x[0-9a-fA-F]{2}|\\[0-7]{3}|\\[abtnvfr]`)
91 // replaceUnicode converts hexadecimal Unicode codepoint notations to a one-rune string.
92 // It assumes the input string is correctly formatted.
93 func replaceUnicode(s string) string {
95 r, _ := strconv.ParseInt(s[3:len(s)-1], 16, 32)
98 r, _, _, _ := strconv.UnquoteChar(s, 0)