2015-10-05 14:22:57 +08:00
|
|
|
// Copyright 2015 The TCell Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the license at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package encoding
|
|
|
|
|
|
|
|
import (
|
2015-10-10 03:24:29 +08:00
|
|
|
"github.com/gdamore/encoding"
|
2020-08-26 07:20:58 +08:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2015-10-05 14:22:57 +08:00
|
|
|
|
|
|
|
"golang.org/x/text/encoding/charmap"
|
|
|
|
"golang.org/x/text/encoding/japanese"
|
|
|
|
"golang.org/x/text/encoding/korean"
|
|
|
|
"golang.org/x/text/encoding/simplifiedchinese"
|
|
|
|
"golang.org/x/text/encoding/traditionalchinese"
|
|
|
|
)
|
|
|
|
|
2015-10-08 11:15:33 +08:00
|
|
|
// Register registers all known encodings. This is a short-cut to
|
|
|
|
// add full character set support to your program. Note that this can
|
2018-06-08 11:53:23 +08:00
|
|
|
// add several megabytes to your program's size, because some of the encodings
|
2015-10-08 11:15:33 +08:00
|
|
|
// are rather large (particularly those from East Asia.)
|
2015-10-05 14:22:57 +08:00
|
|
|
func Register() {
|
2015-10-08 11:15:33 +08:00
|
|
|
// We supply latin1 and latin5, because Go doesn't
|
2015-10-10 03:24:29 +08:00
|
|
|
tcell.RegisterEncoding("ISO8859-1", encoding.ISO8859_1)
|
|
|
|
tcell.RegisterEncoding("ISO8859-9", encoding.ISO8859_9)
|
2015-10-08 11:15:33 +08:00
|
|
|
|
|
|
|
tcell.RegisterEncoding("ISO8859-10", charmap.ISO8859_10)
|
2015-10-05 14:22:57 +08:00
|
|
|
tcell.RegisterEncoding("ISO8859-13", charmap.ISO8859_13)
|
|
|
|
tcell.RegisterEncoding("ISO8859-14", charmap.ISO8859_14)
|
|
|
|
tcell.RegisterEncoding("ISO8859-15", charmap.ISO8859_15)
|
|
|
|
tcell.RegisterEncoding("ISO8859-16", charmap.ISO8859_16)
|
|
|
|
tcell.RegisterEncoding("ISO8859-2", charmap.ISO8859_2)
|
|
|
|
tcell.RegisterEncoding("ISO8859-3", charmap.ISO8859_3)
|
|
|
|
tcell.RegisterEncoding("ISO8859-4", charmap.ISO8859_4)
|
|
|
|
tcell.RegisterEncoding("ISO8859-5", charmap.ISO8859_5)
|
|
|
|
tcell.RegisterEncoding("ISO8859-6", charmap.ISO8859_6)
|
|
|
|
tcell.RegisterEncoding("ISO8859-7", charmap.ISO8859_7)
|
|
|
|
tcell.RegisterEncoding("ISO8859-8", charmap.ISO8859_8)
|
|
|
|
tcell.RegisterEncoding("KOI8-R", charmap.KOI8R)
|
|
|
|
tcell.RegisterEncoding("KOI8-U", charmap.KOI8U)
|
|
|
|
|
|
|
|
// Asian stuff
|
|
|
|
tcell.RegisterEncoding("EUC-JP", japanese.EUCJP)
|
2015-10-08 11:15:33 +08:00
|
|
|
tcell.RegisterEncoding("SHIFT_JIS", japanese.ShiftJIS)
|
2015-10-05 14:22:57 +08:00
|
|
|
tcell.RegisterEncoding("ISO2022JP", japanese.ISO2022JP)
|
|
|
|
|
|
|
|
tcell.RegisterEncoding("EUC-KR", korean.EUCKR)
|
|
|
|
|
|
|
|
tcell.RegisterEncoding("GB18030", simplifiedchinese.GB18030)
|
|
|
|
tcell.RegisterEncoding("GB2312", simplifiedchinese.HZGB2312)
|
|
|
|
tcell.RegisterEncoding("GBK", simplifiedchinese.GBK)
|
|
|
|
|
|
|
|
tcell.RegisterEncoding("Big5", traditionalchinese.Big5)
|
|
|
|
|
|
|
|
// Common aliaess
|
|
|
|
aliases := map[string]string{
|
2015-10-05 16:27:55 +08:00
|
|
|
"8859-1": "ISO8859-1",
|
|
|
|
"ISO-8859-1": "ISO8859-1",
|
|
|
|
"8859-13": "ISO8859-13",
|
|
|
|
"ISO-8859-13": "ISO8859-13",
|
|
|
|
"8859-14": "ISO8859-14",
|
|
|
|
"ISO-8859-14": "ISO8859-14",
|
|
|
|
"8859-15": "ISO8859-15",
|
|
|
|
"ISO-8859-15": "ISO8859-15",
|
|
|
|
"8859-16": "ISO8859-16",
|
|
|
|
"ISO-8859-16": "ISO8859-16",
|
|
|
|
"8859-2": "ISO8859-2",
|
|
|
|
"ISO-8859-2": "ISO8859-2",
|
|
|
|
"8859-3": "ISO8859-3",
|
|
|
|
"ISO-8859-3": "ISO8859-3",
|
|
|
|
"8859-4": "ISO8859-4",
|
|
|
|
"ISO-8859-4": "ISO8859-4",
|
|
|
|
"8859-5": "ISO8859-5",
|
|
|
|
"ISO-8859-5": "ISO8859-5",
|
|
|
|
"8859-6": "ISO8859-6",
|
|
|
|
"ISO-8859-6": "ISO8859-6",
|
|
|
|
"8859-7": "ISO8859-7",
|
|
|
|
"ISO-8859-7": "ISO8859-7",
|
|
|
|
"8859-8": "ISO8859-8",
|
|
|
|
"ISO-8859-8": "ISO8859-8",
|
2015-10-08 11:15:33 +08:00
|
|
|
"8859-9": "ISO8859-9",
|
|
|
|
"ISO-8859-9": "ISO8859-9",
|
2015-10-05 14:22:57 +08:00
|
|
|
|
2015-10-05 16:27:55 +08:00
|
|
|
"SJIS": "Shift_JIS",
|
2015-10-08 11:15:33 +08:00
|
|
|
"EUCJP": "EUC-JP",
|
2015-10-05 16:27:55 +08:00
|
|
|
"2022-JP": "ISO2022JP",
|
|
|
|
"ISO-2022-JP": "ISO2022JP",
|
2015-10-05 14:22:57 +08:00
|
|
|
|
2015-10-08 11:15:33 +08:00
|
|
|
"EUCKR": "EUC-KR",
|
|
|
|
|
|
|
|
// ISO646 isn't quite exactly ASCII, but the 1991 IRV
|
|
|
|
// (international reference version) is so. This helps
|
|
|
|
// some older systems that may use "646" for POSIX locales.
|
|
|
|
"646": "US-ASCII",
|
|
|
|
"ISO646": "US-ASCII",
|
|
|
|
|
|
|
|
// Other names for UTF-8
|
|
|
|
"UTF8": "UTF-8",
|
2015-10-05 14:22:57 +08:00
|
|
|
}
|
|
|
|
for n, v := range aliases {
|
2015-10-08 11:15:33 +08:00
|
|
|
if enc := tcell.GetEncoding(v); enc != nil {
|
|
|
|
tcell.RegisterEncoding(n, enc)
|
|
|
|
}
|
2015-10-05 14:22:57 +08:00
|
|
|
}
|
|
|
|
}
|