forked from aclindsa/ofxgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
25 lines (23 loc) · 579 Bytes
/
util.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
package ofxgo
import (
"bytes"
"github.com/aclindsa/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
}
}
}