mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-11-14 17:20:04 -05:00
26 lines
593 B
Go
26 lines
593 B
Go
|
package ofxgo
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"github.com/golang/go/src/encoding/xml"
|
||
|
)
|
||
|
|
||
|
// Returns the next available Token from the xml.Decoder that is not CharData
|
||
|
// made up entirely of whitespace. This is useful to skip whitespace when
|
||
|
// manually unmarshaling XML.
|
||
|
func nextNonWhitespaceToken(decoder *xml.Decoder) (xml.Token, error) {
|
||
|
for {
|
||
|
tok, err := decoder.Token()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
} else if chars, ok := tok.(xml.CharData); ok {
|
||
|
strippedBytes := bytes.TrimSpace(chars)
|
||
|
if len(strippedBytes) != 0 {
|
||
|
return tok, nil
|
||
|
}
|
||
|
} else {
|
||
|
return tok, nil
|
||
|
}
|
||
|
}
|
||
|
}
|