encoding/charmap: add DecodeByte, EncodeRune methods.

Also change exported values' types from encoding.Encoding (an interface)
to *Charmap (a newly exported struct type), since we can't add methods
to that interface type.

Also fix a few "go vet" issues.

Fixes golang/go#19584

Change-Id: I32f726a791f39c158a782ed013b1d358f0b77e57
Reviewed-on: https://go-review.googlesource.com/38873
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/charmap/charmap.go b/encoding/charmap/charmap.go
index 6e62a83..e89ff07 100644
--- a/encoding/charmap/charmap.go
+++ b/encoding/charmap/charmap.go
@@ -33,32 +33,32 @@
 	ISO8859_8I encoding.Encoding = &iso8859_8I
 
 	iso8859_6E = internal.Encoding{
-		ISO8859_6,
-		"ISO-8859-6E",
-		identifier.ISO88596E,
+		Encoding: ISO8859_6,
+		Name:     "ISO-8859-6E",
+		MIB:      identifier.ISO88596E,
 	}
 
 	iso8859_6I = internal.Encoding{
-		ISO8859_6,
-		"ISO-8859-6I",
-		identifier.ISO88596I,
+		Encoding: ISO8859_6,
+		Name:     "ISO-8859-6I",
+		MIB:      identifier.ISO88596I,
 	}
 
 	iso8859_8E = internal.Encoding{
-		ISO8859_8,
-		"ISO-8859-8E",
-		identifier.ISO88598E,
+		Encoding: ISO8859_8,
+		Name:     "ISO-8859-8E",
+		MIB:      identifier.ISO88598E,
 	}
 
 	iso8859_8I = internal.Encoding{
-		ISO8859_8,
-		"ISO-8859-8I",
-		identifier.ISO88598I,
+		Encoding: ISO8859_8,
+		Name:     "ISO-8859-8I",
+		MIB:      identifier.ISO88598I,
 	}
 )
 
 // All is a list of all defined encodings in this package.
-var All = listAll
+var All []encoding.Encoding = listAll
 
 // TODO: implement these encodings, in order of importance.
 // ASCII, ISO8859_1:       Rather common. Close to Windows 1252.
@@ -70,8 +70,8 @@
 	data [3]byte
 }
 
-// charmap describes an 8-bit character set encoding.
-type charmap struct {
+// Charmap is an 8-bit character set encoding.
+type Charmap struct {
 	// name is the encoding's name.
 	name string
 	// mib is the encoding type of this encoder.
@@ -79,7 +79,7 @@
 	// asciiSuperset states whether the encoding is a superset of ASCII.
 	asciiSuperset bool
 	// low is the lower bound of the encoded byte for a non-ASCII rune. If
-	// charmap.asciiSuperset is true then this will be 0x80, otherwise 0x00.
+	// Charmap.asciiSuperset is true then this will be 0x80, otherwise 0x00.
 	low uint8
 	// replacement is the encoded replacement character.
 	replacement byte
@@ -91,26 +91,30 @@
 	encode [256]uint32
 }
 
-func (m *charmap) NewDecoder() *encoding.Decoder {
+// NewDecoder implements the encoding.Encoding interface.
+func (m *Charmap) NewDecoder() *encoding.Decoder {
 	return &encoding.Decoder{Transformer: charmapDecoder{charmap: m}}
 }
 
-func (m *charmap) NewEncoder() *encoding.Encoder {
+// NewEncoder implements the encoding.Encoding interface.
+func (m *Charmap) NewEncoder() *encoding.Encoder {
 	return &encoding.Encoder{Transformer: charmapEncoder{charmap: m}}
 }
 
-func (m *charmap) String() string {
+// String returns the Charmap's name.
+func (m *Charmap) String() string {
 	return m.name
 }
 
-func (m *charmap) ID() (mib identifier.MIB, other string) {
+// ID implements an internal interface.
+func (m *Charmap) ID() (mib identifier.MIB, other string) {
 	return m.mib, ""
 }
 
 // charmapDecoder implements transform.Transformer by decoding to UTF-8.
 type charmapDecoder struct {
 	transform.NopResetter
-	charmap *charmap
+	charmap *Charmap
 }
 
 func (m charmapDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
@@ -142,10 +146,22 @@
 	return nDst, nSrc, err
 }
 
+// DecodeByte returns the Charmap's rune decoding of the byte b.
+func (m *Charmap) DecodeByte(b byte) rune {
+	switch x := &m.decode[b]; x.len {
+	case 1:
+		return rune(x.data[0])
+	case 2:
+		return rune(x.data[0]&0x1f)<<6 | rune(x.data[1]&0x3f)
+	default:
+		return rune(x.data[0]&0x0f)<<12 | rune(x.data[1]&0x3f)<<6 | rune(x.data[2]&0x3f)
+	}
+}
+
 // charmapEncoder implements transform.Transformer by encoding from UTF-8.
 type charmapEncoder struct {
 	transform.NopResetter
-	charmap *charmap
+	charmap *Charmap
 }
 
 func (m charmapEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
@@ -207,3 +223,27 @@
 	}
 	return nDst, nSrc, err
 }
+
+// EncodeRune returns the Charmap's byte encoding of the rune r. ok is whether
+// r is in the Charmap's repertoire. If not, b is set to the Charmap's
+// replacement byte. This is often the ASCII substitute character '\x1a'.
+func (m *Charmap) EncodeRune(r rune) (b byte, ok bool) {
+	if r < utf8.RuneSelf && m.asciiSuperset {
+		return byte(r), true
+	}
+	for low, high := int(m.low), 0x100; ; {
+		if low >= high {
+			return m.replacement, false
+		}
+		mid := (low + high) / 2
+		got := m.encode[mid]
+		gotRune := rune(got & (1<<24 - 1))
+		if gotRune < r {
+			low = mid + 1
+		} else if gotRune > r {
+			high = mid
+		} else {
+			return byte(got >> 24), true
+		}
+	}
+}
diff --git a/encoding/charmap/charmap_test.go b/encoding/charmap/charmap_test.go
index 186bf4c..03dd76e 100644
--- a/encoding/charmap/charmap_test.go
+++ b/encoding/charmap/charmap_test.go
@@ -16,9 +16,11 @@
 func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
 	return "Decode", e.NewDecoder(), nil
 }
+
 func encASCIISuperset(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
 	return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
 }
+
 func encEBCDIC(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
 	return "Encode", e.NewEncoder(), internal.RepertoireError(0x3f)
 }
@@ -200,6 +202,57 @@
 	}
 }
 
+var windows1255TestCases = []struct {
+	b  byte
+	ok bool
+	r  rune
+}{
+	{'\x00', true, '\u0000'},
+	{'\x1a', true, '\u001a'},
+	{'\x61', true, '\u0061'},
+	{'\x7f', true, '\u007f'},
+	{'\x80', true, '\u20ac'},
+	{'\x95', true, '\u2022'},
+	{'\xa0', true, '\u00a0'},
+	{'\xc0', true, '\u05b0'},
+	{'\xfc', true, '\ufffd'},
+	{'\xfd', true, '\u200e'},
+	{'\xfe', true, '\u200f'},
+	{'\xff', true, '\ufffd'},
+	{encoding.ASCIISub, false, '\u0400'},
+	{encoding.ASCIISub, false, '\u2603'},
+	{encoding.ASCIISub, false, '\U0001f4a9'},
+}
+
+func TestDecodeByte(t *testing.T) {
+	for _, tc := range windows1255TestCases {
+		if !tc.ok {
+			continue
+		}
+
+		got := Windows1255.DecodeByte(tc.b)
+		want := tc.r
+		if got != want {
+			t.Errorf("DecodeByte(%#02x): got %#08x, want %#08x", tc.b, got, want)
+		}
+	}
+}
+
+func TestEncodeRune(t *testing.T) {
+	for _, tc := range windows1255TestCases {
+		// There can be multiple tc.b values that map to tc.r = '\ufffd'.
+		if tc.r == '\ufffd' {
+			continue
+		}
+
+		gotB, gotOK := Windows1255.EncodeRune(tc.r)
+		wantB, wantOK := tc.b, tc.ok
+		if gotB != wantB || gotOK != wantOK {
+			t.Errorf("EncodeRune(%#08x): got (%#02x, %t), want (%#02x, %t)", tc.r, gotB, gotOK, wantB, wantOK)
+		}
+	}
+}
+
 func TestFiles(t *testing.T) { enctest.TestFile(t, Windows1252) }
 
 func BenchmarkEncoding(b *testing.B) { enctest.Benchmark(b, Windows1252) }
diff --git a/encoding/charmap/maketables.go b/encoding/charmap/maketables.go
index a691acb..f794170 100644
--- a/encoding/charmap/maketables.go
+++ b/encoding/charmap/maketables.go
@@ -494,7 +494,7 @@
 		if e.comment != "" {
 			printf("//\n// %s\n", e.comment)
 		}
-		printf("var %s encoding.Encoding = &%s\n\nvar %s = charmap{\nname: %q,\n",
+		printf("var %s *Charmap = &%s\n\nvar %s = Charmap{\nname: %q,\n",
 			varName, lowerVarName, lowerVarName, e.name)
 		if mibs[e.mib] {
 			log.Fatalf("MIB type %q declared multiple times.", e.mib)
@@ -540,7 +540,7 @@
 		}
 		printf("},\n}\n")
 
-		// Add an estimate of the size of a single charmap{} struct value, which
+		// Add an estimate of the size of a single Charmap{} struct value, which
 		// includes two 256 elem arrays of 4 bytes and some extra fields, which
 		// align to 3 uint64s on 64-bit architectures.
 		w.Size += 2*4*256 + 3*8
diff --git a/encoding/charmap/tables.go b/encoding/charmap/tables.go
index fc80726..cf7281e 100644
--- a/encoding/charmap/tables.go
+++ b/encoding/charmap/tables.go
@@ -8,9 +8,9 @@
 )
 
 // CodePage037 is the IBM Code Page 037 encoding.
-var CodePage037 encoding.Encoding = &codePage037
+var CodePage037 *Charmap = &codePage037
 
-var codePage037 = charmap{
+var codePage037 = Charmap{
 	name:          "IBM Code Page 037",
 	mib:           identifier.IBM037,
 	asciiSuperset: false,
@@ -183,9 +183,9 @@
 }
 
 // CodePage437 is the IBM Code Page 437 encoding.
-var CodePage437 encoding.Encoding = &codePage437
+var CodePage437 *Charmap = &codePage437
 
-var codePage437 = charmap{
+var codePage437 = Charmap{
 	name:          "IBM Code Page 437",
 	mib:           identifier.PC8CodePage437,
 	asciiSuperset: true,
@@ -358,9 +358,9 @@
 }
 
 // CodePage850 is the IBM Code Page 850 encoding.
-var CodePage850 encoding.Encoding = &codePage850
+var CodePage850 *Charmap = &codePage850
 
-var codePage850 = charmap{
+var codePage850 = Charmap{
 	name:          "IBM Code Page 850",
 	mib:           identifier.PC850Multilingual,
 	asciiSuperset: true,
@@ -533,9 +533,9 @@
 }
 
 // CodePage852 is the IBM Code Page 852 encoding.
-var CodePage852 encoding.Encoding = &codePage852
+var CodePage852 *Charmap = &codePage852
 
-var codePage852 = charmap{
+var codePage852 = Charmap{
 	name:          "IBM Code Page 852",
 	mib:           identifier.PCp852,
 	asciiSuperset: true,
@@ -708,9 +708,9 @@
 }
 
 // CodePage855 is the IBM Code Page 855 encoding.
-var CodePage855 encoding.Encoding = &codePage855
+var CodePage855 *Charmap = &codePage855
 
-var codePage855 = charmap{
+var codePage855 = Charmap{
 	name:          "IBM Code Page 855",
 	mib:           identifier.IBM855,
 	asciiSuperset: true,
@@ -883,9 +883,9 @@
 }
 
 // CodePage858 is the Windows Code Page 858 encoding.
-var CodePage858 encoding.Encoding = &codePage858
+var CodePage858 *Charmap = &codePage858
 
-var codePage858 = charmap{
+var codePage858 = Charmap{
 	name:          "Windows Code Page 858",
 	mib:           identifier.IBM00858,
 	asciiSuperset: true,
@@ -1058,9 +1058,9 @@
 }
 
 // CodePage860 is the IBM Code Page 860 encoding.
-var CodePage860 encoding.Encoding = &codePage860
+var CodePage860 *Charmap = &codePage860
 
-var codePage860 = charmap{
+var codePage860 = Charmap{
 	name:          "IBM Code Page 860",
 	mib:           identifier.IBM860,
 	asciiSuperset: true,
@@ -1233,9 +1233,9 @@
 }
 
 // CodePage862 is the IBM Code Page 862 encoding.
-var CodePage862 encoding.Encoding = &codePage862
+var CodePage862 *Charmap = &codePage862
 
-var codePage862 = charmap{
+var codePage862 = Charmap{
 	name:          "IBM Code Page 862",
 	mib:           identifier.PC862LatinHebrew,
 	asciiSuperset: true,
@@ -1408,9 +1408,9 @@
 }
 
 // CodePage863 is the IBM Code Page 863 encoding.
-var CodePage863 encoding.Encoding = &codePage863
+var CodePage863 *Charmap = &codePage863
 
-var codePage863 = charmap{
+var codePage863 = Charmap{
 	name:          "IBM Code Page 863",
 	mib:           identifier.IBM863,
 	asciiSuperset: true,
@@ -1583,9 +1583,9 @@
 }
 
 // CodePage865 is the IBM Code Page 865 encoding.
-var CodePage865 encoding.Encoding = &codePage865
+var CodePage865 *Charmap = &codePage865
 
-var codePage865 = charmap{
+var codePage865 = Charmap{
 	name:          "IBM Code Page 865",
 	mib:           identifier.IBM865,
 	asciiSuperset: true,
@@ -1758,9 +1758,9 @@
 }
 
 // CodePage866 is the IBM Code Page 866 encoding.
-var CodePage866 encoding.Encoding = &codePage866
+var CodePage866 *Charmap = &codePage866
 
-var codePage866 = charmap{
+var codePage866 = Charmap{
 	name:          "IBM Code Page 866",
 	mib:           identifier.IBM866,
 	asciiSuperset: true,
@@ -1933,9 +1933,9 @@
 }
 
 // CodePage1047 is the IBM Code Page 1047 encoding.
-var CodePage1047 encoding.Encoding = &codePage1047
+var CodePage1047 *Charmap = &codePage1047
 
-var codePage1047 = charmap{
+var codePage1047 = Charmap{
 	name:          "IBM Code Page 1047",
 	mib:           identifier.IBM1047,
 	asciiSuperset: false,
@@ -2108,9 +2108,9 @@
 }
 
 // CodePage1140 is the IBM Code Page 1140 encoding.
-var CodePage1140 encoding.Encoding = &codePage1140
+var CodePage1140 *Charmap = &codePage1140
 
-var codePage1140 = charmap{
+var codePage1140 = Charmap{
 	name:          "IBM Code Page 1140",
 	mib:           identifier.IBM01140,
 	asciiSuperset: false,
@@ -2283,9 +2283,9 @@
 }
 
 // ISO8859_1 is the ISO 8859-1 encoding.
-var ISO8859_1 encoding.Encoding = &iso8859_1
+var ISO8859_1 *Charmap = &iso8859_1
 
-var iso8859_1 = charmap{
+var iso8859_1 = Charmap{
 	name:          "ISO 8859-1",
 	mib:           identifier.ISOLatin1,
 	asciiSuperset: true,
@@ -2458,9 +2458,9 @@
 }
 
 // ISO8859_2 is the ISO 8859-2 encoding.
-var ISO8859_2 encoding.Encoding = &iso8859_2
+var ISO8859_2 *Charmap = &iso8859_2
 
-var iso8859_2 = charmap{
+var iso8859_2 = Charmap{
 	name:          "ISO 8859-2",
 	mib:           identifier.ISOLatin2,
 	asciiSuperset: true,
@@ -2633,9 +2633,9 @@
 }
 
 // ISO8859_3 is the ISO 8859-3 encoding.
-var ISO8859_3 encoding.Encoding = &iso8859_3
+var ISO8859_3 *Charmap = &iso8859_3
 
-var iso8859_3 = charmap{
+var iso8859_3 = Charmap{
 	name:          "ISO 8859-3",
 	mib:           identifier.ISOLatin3,
 	asciiSuperset: true,
@@ -2808,9 +2808,9 @@
 }
 
 // ISO8859_4 is the ISO 8859-4 encoding.
-var ISO8859_4 encoding.Encoding = &iso8859_4
+var ISO8859_4 *Charmap = &iso8859_4
 
-var iso8859_4 = charmap{
+var iso8859_4 = Charmap{
 	name:          "ISO 8859-4",
 	mib:           identifier.ISOLatin4,
 	asciiSuperset: true,
@@ -2983,9 +2983,9 @@
 }
 
 // ISO8859_5 is the ISO 8859-5 encoding.
-var ISO8859_5 encoding.Encoding = &iso8859_5
+var ISO8859_5 *Charmap = &iso8859_5
 
-var iso8859_5 = charmap{
+var iso8859_5 = Charmap{
 	name:          "ISO 8859-5",
 	mib:           identifier.ISOLatinCyrillic,
 	asciiSuperset: true,
@@ -3158,9 +3158,9 @@
 }
 
 // ISO8859_6 is the ISO 8859-6 encoding.
-var ISO8859_6 encoding.Encoding = &iso8859_6
+var ISO8859_6 *Charmap = &iso8859_6
 
-var iso8859_6 = charmap{
+var iso8859_6 = Charmap{
 	name:          "ISO 8859-6",
 	mib:           identifier.ISOLatinArabic,
 	asciiSuperset: true,
@@ -3333,9 +3333,9 @@
 }
 
 // ISO8859_7 is the ISO 8859-7 encoding.
-var ISO8859_7 encoding.Encoding = &iso8859_7
+var ISO8859_7 *Charmap = &iso8859_7
 
-var iso8859_7 = charmap{
+var iso8859_7 = Charmap{
 	name:          "ISO 8859-7",
 	mib:           identifier.ISOLatinGreek,
 	asciiSuperset: true,
@@ -3508,9 +3508,9 @@
 }
 
 // ISO8859_8 is the ISO 8859-8 encoding.
-var ISO8859_8 encoding.Encoding = &iso8859_8
+var ISO8859_8 *Charmap = &iso8859_8
 
-var iso8859_8 = charmap{
+var iso8859_8 = Charmap{
 	name:          "ISO 8859-8",
 	mib:           identifier.ISOLatinHebrew,
 	asciiSuperset: true,
@@ -3683,9 +3683,9 @@
 }
 
 // ISO8859_9 is the ISO 8859-9 encoding.
-var ISO8859_9 encoding.Encoding = &iso8859_9
+var ISO8859_9 *Charmap = &iso8859_9
 
-var iso8859_9 = charmap{
+var iso8859_9 = Charmap{
 	name:          "ISO 8859-9",
 	mib:           identifier.ISOLatin5,
 	asciiSuperset: true,
@@ -3858,9 +3858,9 @@
 }
 
 // ISO8859_10 is the ISO 8859-10 encoding.
-var ISO8859_10 encoding.Encoding = &iso8859_10
+var ISO8859_10 *Charmap = &iso8859_10
 
-var iso8859_10 = charmap{
+var iso8859_10 = Charmap{
 	name:          "ISO 8859-10",
 	mib:           identifier.ISOLatin6,
 	asciiSuperset: true,
@@ -4033,9 +4033,9 @@
 }
 
 // ISO8859_13 is the ISO 8859-13 encoding.
-var ISO8859_13 encoding.Encoding = &iso8859_13
+var ISO8859_13 *Charmap = &iso8859_13
 
-var iso8859_13 = charmap{
+var iso8859_13 = Charmap{
 	name:          "ISO 8859-13",
 	mib:           identifier.ISO885913,
 	asciiSuperset: true,
@@ -4208,9 +4208,9 @@
 }
 
 // ISO8859_14 is the ISO 8859-14 encoding.
-var ISO8859_14 encoding.Encoding = &iso8859_14
+var ISO8859_14 *Charmap = &iso8859_14
 
-var iso8859_14 = charmap{
+var iso8859_14 = Charmap{
 	name:          "ISO 8859-14",
 	mib:           identifier.ISO885914,
 	asciiSuperset: true,
@@ -4383,9 +4383,9 @@
 }
 
 // ISO8859_15 is the ISO 8859-15 encoding.
-var ISO8859_15 encoding.Encoding = &iso8859_15
+var ISO8859_15 *Charmap = &iso8859_15
 
-var iso8859_15 = charmap{
+var iso8859_15 = Charmap{
 	name:          "ISO 8859-15",
 	mib:           identifier.ISO885915,
 	asciiSuperset: true,
@@ -4558,9 +4558,9 @@
 }
 
 // ISO8859_16 is the ISO 8859-16 encoding.
-var ISO8859_16 encoding.Encoding = &iso8859_16
+var ISO8859_16 *Charmap = &iso8859_16
 
-var iso8859_16 = charmap{
+var iso8859_16 = Charmap{
 	name:          "ISO 8859-16",
 	mib:           identifier.ISO885916,
 	asciiSuperset: true,
@@ -4733,9 +4733,9 @@
 }
 
 // KOI8R is the KOI8-R encoding.
-var KOI8R encoding.Encoding = &koi8R
+var KOI8R *Charmap = &koi8R
 
-var koi8R = charmap{
+var koi8R = Charmap{
 	name:          "KOI8-R",
 	mib:           identifier.KOI8R,
 	asciiSuperset: true,
@@ -4908,9 +4908,9 @@
 }
 
 // KOI8U is the KOI8-U encoding.
-var KOI8U encoding.Encoding = &koi8U
+var KOI8U *Charmap = &koi8U
 
-var koi8U = charmap{
+var koi8U = Charmap{
 	name:          "KOI8-U",
 	mib:           identifier.KOI8U,
 	asciiSuperset: true,
@@ -5083,9 +5083,9 @@
 }
 
 // Macintosh is the Macintosh encoding.
-var Macintosh encoding.Encoding = &macintosh
+var Macintosh *Charmap = &macintosh
 
-var macintosh = charmap{
+var macintosh = Charmap{
 	name:          "Macintosh",
 	mib:           identifier.Macintosh,
 	asciiSuperset: true,
@@ -5258,9 +5258,9 @@
 }
 
 // MacintoshCyrillic is the Macintosh Cyrillic encoding.
-var MacintoshCyrillic encoding.Encoding = &macintoshCyrillic
+var MacintoshCyrillic *Charmap = &macintoshCyrillic
 
-var macintoshCyrillic = charmap{
+var macintoshCyrillic = Charmap{
 	name:          "Macintosh Cyrillic",
 	mib:           identifier.MacintoshCyrillic,
 	asciiSuperset: true,
@@ -5433,9 +5433,9 @@
 }
 
 // Windows874 is the Windows 874 encoding.
-var Windows874 encoding.Encoding = &windows874
+var Windows874 *Charmap = &windows874
 
-var windows874 = charmap{
+var windows874 = Charmap{
 	name:          "Windows 874",
 	mib:           identifier.Windows874,
 	asciiSuperset: true,
@@ -5608,9 +5608,9 @@
 }
 
 // Windows1250 is the Windows 1250 encoding.
-var Windows1250 encoding.Encoding = &windows1250
+var Windows1250 *Charmap = &windows1250
 
-var windows1250 = charmap{
+var windows1250 = Charmap{
 	name:          "Windows 1250",
 	mib:           identifier.Windows1250,
 	asciiSuperset: true,
@@ -5783,9 +5783,9 @@
 }
 
 // Windows1251 is the Windows 1251 encoding.
-var Windows1251 encoding.Encoding = &windows1251
+var Windows1251 *Charmap = &windows1251
 
-var windows1251 = charmap{
+var windows1251 = Charmap{
 	name:          "Windows 1251",
 	mib:           identifier.Windows1251,
 	asciiSuperset: true,
@@ -5958,9 +5958,9 @@
 }
 
 // Windows1252 is the Windows 1252 encoding.
-var Windows1252 encoding.Encoding = &windows1252
+var Windows1252 *Charmap = &windows1252
 
-var windows1252 = charmap{
+var windows1252 = Charmap{
 	name:          "Windows 1252",
 	mib:           identifier.Windows1252,
 	asciiSuperset: true,
@@ -6133,9 +6133,9 @@
 }
 
 // Windows1253 is the Windows 1253 encoding.
-var Windows1253 encoding.Encoding = &windows1253
+var Windows1253 *Charmap = &windows1253
 
-var windows1253 = charmap{
+var windows1253 = Charmap{
 	name:          "Windows 1253",
 	mib:           identifier.Windows1253,
 	asciiSuperset: true,
@@ -6308,9 +6308,9 @@
 }
 
 // Windows1254 is the Windows 1254 encoding.
-var Windows1254 encoding.Encoding = &windows1254
+var Windows1254 *Charmap = &windows1254
 
-var windows1254 = charmap{
+var windows1254 = Charmap{
 	name:          "Windows 1254",
 	mib:           identifier.Windows1254,
 	asciiSuperset: true,
@@ -6483,9 +6483,9 @@
 }
 
 // Windows1255 is the Windows 1255 encoding.
-var Windows1255 encoding.Encoding = &windows1255
+var Windows1255 *Charmap = &windows1255
 
-var windows1255 = charmap{
+var windows1255 = Charmap{
 	name:          "Windows 1255",
 	mib:           identifier.Windows1255,
 	asciiSuperset: true,
@@ -6658,9 +6658,9 @@
 }
 
 // Windows1256 is the Windows 1256 encoding.
-var Windows1256 encoding.Encoding = &windows1256
+var Windows1256 *Charmap = &windows1256
 
-var windows1256 = charmap{
+var windows1256 = Charmap{
 	name:          "Windows 1256",
 	mib:           identifier.Windows1256,
 	asciiSuperset: true,
@@ -6833,9 +6833,9 @@
 }
 
 // Windows1257 is the Windows 1257 encoding.
-var Windows1257 encoding.Encoding = &windows1257
+var Windows1257 *Charmap = &windows1257
 
-var windows1257 = charmap{
+var windows1257 = Charmap{
 	name:          "Windows 1257",
 	mib:           identifier.Windows1257,
 	asciiSuperset: true,
@@ -7008,9 +7008,9 @@
 }
 
 // Windows1258 is the Windows 1258 encoding.
-var Windows1258 encoding.Encoding = &windows1258
+var Windows1258 *Charmap = &windows1258
 
-var windows1258 = charmap{
+var windows1258 = Charmap{
 	name:          "Windows 1258",
 	mib:           identifier.Windows1258,
 	asciiSuperset: true,
@@ -7185,9 +7185,9 @@
 // XUserDefined is the X-User-Defined encoding.
 //
 // It is defined at http://encoding.spec.whatwg.org/#x-user-defined
-var XUserDefined encoding.Encoding = &xUserDefined
+var XUserDefined *Charmap = &xUserDefined
 
-var xUserDefined = charmap{
+var xUserDefined = Charmap{
 	name:          "X-User-Defined",
 	mib:           identifier.XUserDefined,
 	asciiSuperset: true,