Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(723)

Side by Side Diff: html/charset/encoding.go

Issue 27110043: code review 27110043: go.net/html/charset: new package (Closed)
Patch Set: diff -r 75017ecb835f https://code.google.com/p/go.net Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | html/charset/encoding_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Package charset provides common text encodings for HTML documents.
2 //
3 // The mapping from encoding labels to encodings is defined
4 // at http://encoding.spec.whatwg.org.
5 package charset
6
7 import (
8 "errors"
9 "strings"
10
11 "code.google.com/p/go.text/encoding"
12 "code.google.com/p/go.text/transform"
13 )
14
15 // Encoding returns the encoding with the specified label, or nil if label is
16 // not one of the standard encodings for HTML. Matching is case-insensitive
17 // and ignores leading and trailing whitespace.
18 func Encoding(label string) encoding.Encoding {
19 label = strings.ToLower(strings.Trim(label, "\t\n\r\f "))
20 return encodings[label]
21 }
22
23 type utf8Encoding struct{}
24
25 func (utf8Encoding) NewDecoder() transform.Transformer {
26 return transform.Nop
27 }
28
29 func (utf8Encoding) NewEncoder() transform.Transformer {
30 return transform.Nop
31 }
32
33 var ErrReplacementEncoding = errors.New("charset: ISO-2022-CN and ISO-2022-KR ar e obsolete encodings for HTML")
34
35 type errorTransformer struct {
36 err error
37 }
38
39 func (t errorTransformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int , err error) {
40 return 0, 0, t.err
41 }
42
43 type replacementEncoding struct{}
44
45 func (replacementEncoding) NewDecoder() transform.Transformer {
46 return errorTransformer{ErrReplacementEncoding}
47 }
48
49 func (replacementEncoding) NewEncoder() transform.Transformer {
50 return transform.Nop
51 }
OLDNEW
« no previous file with comments | « no previous file | html/charset/encoding_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b