rss/charset_reader.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package rss import ( "errors" "io" "strings" "github.com/axgle/mahonia" ) func charsetReader(charset string, input io.Reader) (io.Reader, error) { switch { case isCharsetUTF8(charset): return input, nil case isCharsetISO88591(charset): return newCharsetISO88591(input), nil default: if decoder := mahonia.NewDecoder(charset); decoder != nil { return decoder.NewReader(input), nil } } return nil, errors.New("CharsetReader: unexpected charset: " + charset) } func isCharset(charset string, names []string) bool { charset = strings.ToLower(charset) for _, n := range names { if charset == strings.ToLower(n) { return true } } return false } func isCharsetUTF8(charset string) bool { names := []string{ "UTF-8", // Default "", } return isCharset(charset, names) }