Skip to content

Commit

Permalink
cleen up duplicate method
Browse files Browse the repository at this point in the history
  • Loading branch information
clbanning committed Oct 12, 2020
1 parent b2dcb00 commit b957cfd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
37 changes: 37 additions & 0 deletions deprecate/stuff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// ======================== newMapToXmlIndent

func (mv Map) MarshalXml(rootTag ...string) ([]byte, error) {
m := map[string]interface{}(mv)
var err error
// s := new(string)
// b := new(strings.Builder)
b := new(bytes.Buffer)
p := new(pretty) // just a stub

if len(m) == 1 && len(rootTag) == 0 {
for key, value := range m {
// if it an array, see if all values are map[string]interface{}
// we force a new root tag if we'll end up with no key:value in the list
// so: key:[string_val, bool:true] --> <doc><key>string_val</key><bool>true</bool></doc>
switch value.(type) {
case []interface{}:
for _, v := range value.([]interface{}) {
switch v.(type) {
case map[string]interface{}: // noop
default: // anything else
err = marshalMapToXmlIndent(false, b, DefaultRootTag, m, p)
goto done
}
}
}
err = marshalMapToXmlIndent(false, b, key, value, p)
}
} else if len(rootTag) == 1 {
err = marshalMapToXmlIndent(false, b, rootTag[0], m, p)
} else {
err = marshalMapToXmlIndent(false, b, DefaultRootTag, m, p)
}
done:
return b.Bytes(), err
}
36 changes: 0 additions & 36 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,39 +1324,3 @@ func (e elemList) Less(i, j int) bool {
return e[i][0].(string) <= e[j][0].(string)
}

// ======================== newMapToXmlIndent

func (mv Map) MarshalXml(rootTag ...string) ([]byte, error) {
m := map[string]interface{}(mv)
var err error
// s := new(string)
// b := new(strings.Builder)
b := new(bytes.Buffer)
p := new(pretty) // just a stub

if len(m) == 1 && len(rootTag) == 0 {
for key, value := range m {
// if it an array, see if all values are map[string]interface{}
// we force a new root tag if we'll end up with no key:value in the list
// so: key:[string_val, bool:true] --> <doc><key>string_val</key><bool>true</bool></doc>
switch value.(type) {
case []interface{}:
for _, v := range value.([]interface{}) {
switch v.(type) {
case map[string]interface{}: // noop
default: // anything else
err = marshalMapToXmlIndent(false, b, DefaultRootTag, m, p)
goto done
}
}
}
err = marshalMapToXmlIndent(false, b, key, value, p)
}
} else if len(rootTag) == 1 {
err = marshalMapToXmlIndent(false, b, rootTag[0], m, p)
} else {
err = marshalMapToXmlIndent(false, b, DefaultRootTag, m, p)
}
done:
return b.Bytes(), err
}

0 comments on commit b957cfd

Please sign in to comment.