1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-10 10:23:19 +08:00

优化代码结构

This commit is contained in:
源文雨
2023-02-08 16:19:09 +08:00
parent d8f39cecf1
commit 7ff4850504
16 changed files with 153 additions and 114 deletions

View File

@@ -76,19 +76,20 @@ func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
switch tt := t.(type) {
case xml.StartElement:
if tt.Name.Local == "rPr" {
switch tt.Name.Local {
case "rPr":
var value RunProperties
d.DecodeElement(&value, &start)
elem.RunProperties = &value
} else if tt.Name.Local == "instrText" {
case "instrText":
var value string
d.DecodeElement(&value, &start)
elem.InstrText = value
} else if tt.Name.Local == "t" {
case "t":
var value Text
d.DecodeElement(&value, &start)
elem.Text = &value
} else {
default:
continue
}
}
@@ -109,8 +110,7 @@ func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
switch tt := t.(type) {
case xml.CharData:
cd := tt.Copy()
elem.Text = string(cd)
elem.Text = string(tt) // implicitly copy
}
}