-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CT_Rst.go
127 lines (119 loc) · 3.33 KB
/
CT_Rst.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package sml
import (
"encoding/xml"
"fmt"
"go.devnw.com/ooxml"
)
type CT_Rst struct {
// Text
T *string
// Rich Text Run
R []*CT_RElt
// Phonetic Run
RPh []*CT_PhoneticRun
// Phonetic Properties
PhoneticPr *CT_PhoneticPr
}
func NewCT_Rst() *CT_Rst {
ret := &CT_Rst{}
return ret
}
func (m *CT_Rst) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeToken(start)
if m.T != nil {
set := xml.StartElement{Name: xml.Name{Local: "ma:t"}}
office.AddPreserveSpaceAttr(&set, *m.T)
e.EncodeElement(m.T, set)
}
if m.R != nil {
ser := xml.StartElement{Name: xml.Name{Local: "ma:r"}}
for _, c := range m.R {
e.EncodeElement(c, ser)
}
}
if m.RPh != nil {
serPh := xml.StartElement{Name: xml.Name{Local: "ma:rPh"}}
for _, c := range m.RPh {
e.EncodeElement(c, serPh)
}
}
if m.PhoneticPr != nil {
sephoneticPr := xml.StartElement{Name: xml.Name{Local: "ma:phoneticPr"}}
e.EncodeElement(m.PhoneticPr, sephoneticPr)
}
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
}
func (m *CT_Rst) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
lCT_Rst:
for {
tok, err := d.Token()
if err != nil {
return err
}
switch el := tok.(type) {
case xml.StartElement:
switch el.Name {
case xml.Name{Space: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", Local: "t"},
xml.Name{Space: "http://purl.oclc.org/ooxml/spreadsheetml/main", Local: "t"}:
m.T = new(string)
if err := d.DecodeElement(m.T, &el); err != nil {
return err
}
case xml.Name{Space: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", Local: "r"},
xml.Name{Space: "http://purl.oclc.org/ooxml/spreadsheetml/main", Local: "r"}:
tmp := NewCT_RElt()
if err := d.DecodeElement(tmp, &el); err != nil {
return err
}
m.R = append(m.R, tmp)
case xml.Name{Space: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", Local: "rPh"},
xml.Name{Space: "http://purl.oclc.org/ooxml/spreadsheetml/main", Local: "rPh"}:
tmp := NewCT_PhoneticRun()
if err := d.DecodeElement(tmp, &el); err != nil {
return err
}
m.RPh = append(m.RPh, tmp)
case xml.Name{Space: "http://schemas.openxmlformats.org/spreadsheetml/2006/main", Local: "phoneticPr"},
xml.Name{Space: "http://purl.oclc.org/ooxml/spreadsheetml/main", Local: "phoneticPr"}:
m.PhoneticPr = NewCT_PhoneticPr()
if err := d.DecodeElement(m.PhoneticPr, &el); err != nil {
return err
}
default:
office.Log("skipping unsupported element on CT_Rst %v", el.Name)
if err := d.Skip(); err != nil {
return err
}
}
case xml.EndElement:
break lCT_Rst
case xml.CharData:
}
}
return nil
}
// Validate validates the CT_Rst and its children
func (m *CT_Rst) Validate() error {
return m.ValidateWithPath("CT_Rst")
}
// ValidateWithPath validates the CT_Rst and its children, prefixing error messages with path
func (m *CT_Rst) ValidateWithPath(path string) error {
for i, v := range m.R {
if err := v.ValidateWithPath(fmt.Sprintf("%s/R[%d]", path, i)); err != nil {
return err
}
}
for i, v := range m.RPh {
if err := v.ValidateWithPath(fmt.Sprintf("%s/RPh[%d]", path, i)); err != nil {
return err
}
}
if m.PhoneticPr != nil {
if err := m.PhoneticPr.ValidateWithPath(path + "/PhoneticPr"); err != nil {
return err
}
}
return nil
}