github.com/quay/claircore@v1.5.28/internal/xmlutil/charset.go (about)

     1  package xmlutil
     2  
     3  import (
     4  	"io"
     5  
     6  	"golang.org/x/text/encoding/ianaindex"
     7  )
     8  
     9  // CharsetReader is a function suitable for using as an xml.Decoder's
    10  // CharsetReader member.
    11  func CharsetReader(charset string, r io.Reader) (io.Reader, error) {
    12  	// equivalence hacks
    13  	switch charset {
    14  	case "ASCII":
    15  		charset = `US-ASCII`
    16  	}
    17  	enc, err := ianaindex.IANA.Encoding(charset)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	return enc.NewDecoder().Reader(r), nil
    22  }