<commit_before>package gpx

import (
	"encoding/xml"
	"errors"
	"fmt"
	"io"
	"strconv"
)

const nsGPX11 = "http://www.topografix.com/GPX/1/1"

var (
	ErrBadRootTag = errors.New("gpx: root element must be <gpx>")
	ErrGPX11Only  = errors.New("gpx: can only parse GPX 1.1 documents")
)

// Decoder decodes a GPX document from an input stream.
type Decoder struct {
	Strict bool
	r      io.Reader
	xd     *xml.Decoder
	ts     tokenStream
}

// NewDecoder creates a new decoder reading from r. The decoder
// operates in strict mode.
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{
		Strict: true,
		r:      r,
	}
}

// Decode decodes a document.
func (d *Decoder) Decode() (doc Document, err error) {
	d.xd = xml.NewDecoder(d.r)
	d.ts = tokenStream{d.xd}

	se, err := d.findGPX()
	if err != nil {
		return doc, err
	}

	return d.consumeGPX(se)
}

func (d *Decoder) findGPX() (se xml.StartElement, err error) {
	for {
		tok, err := d.xd.Token()
		if err != nil {
			return se, err
		}
		if se, ok := tok.(xml.StartElement); ok {
			if se.Name.Local != "gpx" {
				return se, ErrBadRootTag
			}
			if se.Name.Space != nsGPX11 {
				return se, ErrGPX11Only
			}
			return se, nil
		}
	}
}

func (d *Decoder) consumeGPX(se xml.StartElement) (doc Document, err error) {
	for _, a := range se.Attr {
		switch a.Name.Local {
		case "version":
			doc.Version = a.Value
		}<commit_msg>No need to store XML decoder<commit_after>package gpx

import (
	"encoding/xml"
	"errors"
	"fmt"
	"io"
	"strconv"
)

const nsGPX11 = "http://www.topografix.com/GPX/1/1"

var (
	ErrBadRootTag = errors.New("gpx: root element must be <gpx>")
	ErrGPX11Only  = errors.New("gpx: can only parse GPX 1.1 documents")
)

// Decoder decodes a GPX document from an input stream.
type Decoder struct {
	Strict bool
	r      io.Reader
	ts     tokenStream
}

// NewDecoder creates a new decoder reading from r. The decoder
// operates in strict mode.
func NewDecoder(r io.Reader) *Decoder {
	return &Decoder{
		Strict: true,
		r:      r,
	}
}

// Decode decodes a document.
func (d *Decoder) Decode() (doc Document, err error) {
	dec := xml.NewDecoder(d.r)
	d.ts = tokenStream{dec}

	se, err := d.findGPX()
	if err != nil {
		return doc, err
	}

	return d.consumeGPX(se)
}

func (d *Decoder) findGPX() (se xml.StartElement, err error) {
	for {
		tok, err := d.ts.Token()
		if err != nil {
			return se, err
		}
		if se, ok := tok.(xml.StartElement); ok {
			if se.Name.Local != "gpx" {
				return se, ErrBadRootTag
			}
			if se.Name.Space != nsGPX11 {
				return se, ErrGPX11Only
			}
			return se, nil
		}
	}
}

func (d *Decoder) consumeGPX(se xml.StartElement) (doc Document, err error) {
	for _, a := range se.Attr {
		switch a.Name.Local {
		case "version":
			doc.Version = a.Value
		}
{'fraction_non_alphanumeric': 0.13529198404062387, 'fraction_numerical': 0.008705114254624592, 'mean_word_length': 2.94, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 11}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2504704', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1064, 'n_words': 313}