Skip to content

Commit

Permalink
Use TokenTypeInvalid as zero value Token kind
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiburjack committed Feb 14, 2022
1 parent e4fe85f commit bfe1741
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func (thiz *Encoder) Reset(w io.Writer) {
// of this Encoder.
func (thiz *Encoder) EncodeToken(t *Token) error {
switch t.Kind {
case TokenTypeInvalid:
return errors.New("trying to encode invalid/zerovalue token")
case TokenTypeStartElement:
err := thiz.encodeStartElement(t)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions namespaceModifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func (thiz *NamespaceModifier) addPrefixRewrite(original, prefix []byte) {
// will remain unmodified for the lexical scope of the XML element represented
// by that token, as per the documentation of EncoderMiddleware.EncodeToken.
func (thiz NamespaceModifier) NamespaceOfToken(t *Token) []byte {
if t.Kind == TokenTypeInvalid {
return nil
}
prefix := t.Name.Prefix
if len(prefix) > 0 {
alias := thiz.findPrefixAlias(t.Name.Prefix)
Expand Down
3 changes: 2 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type Attr struct {

// constants for Token.Kind
const (
TokenTypeStartElement = iota
TokenTypeInvalid = iota
TokenTypeStartElement
TokenTypeEndElement
TokenTypeProcInst
TokenTypeDirective
Expand Down

0 comments on commit bfe1741

Please sign in to comment.