...

Source file src/github.com/gdamore/tcell/v2/encoding/all.go

Documentation: github.com/gdamore/tcell/v2/encoding

     1  // Copyright 2015 The TCell Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use file except in compliance with the License.
     5  // You may obtain a copy of the license at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package encoding is used to provide a fairly complete set of encodings
    16  // for tcell applications.  Importing this package will automatically
    17  // register encodings.  Note that this package will add several MB to the
    18  // generated binaries, as the encodings themselves can be somewhat large,
    19  // particularly for the East Asian locales.
    20  package encoding
    21  
    22  import (
    23  	"github.com/gdamore/encoding"
    24  	"github.com/gdamore/tcell/v2"
    25  
    26  	"golang.org/x/text/encoding/charmap"
    27  	"golang.org/x/text/encoding/japanese"
    28  	"golang.org/x/text/encoding/korean"
    29  	"golang.org/x/text/encoding/simplifiedchinese"
    30  	"golang.org/x/text/encoding/traditionalchinese"
    31  )
    32  
    33  // Register registers all known encodings.  This is a short-cut to
    34  // add full character set support to your program.  Note that this can
    35  // add several megabytes to your program's size, because some of the encodings
    36  // are rather large (particularly those from East Asia.)
    37  //
    38  // Deprecated: This is no longer needed, importing the package is sufficient.
    39  func Register() {
    40  	registerAll()
    41  }
    42  
    43  func registerAll() {
    44  	// We supply latin1 and latin5, because Go doesn't
    45  	tcell.RegisterEncoding("ISO8859-1", encoding.ISO8859_1)
    46  	tcell.RegisterEncoding("ISO8859-9", encoding.ISO8859_9)
    47  
    48  	tcell.RegisterEncoding("ISO8859-10", charmap.ISO8859_10)
    49  	tcell.RegisterEncoding("ISO8859-13", charmap.ISO8859_13)
    50  	tcell.RegisterEncoding("ISO8859-14", charmap.ISO8859_14)
    51  	tcell.RegisterEncoding("ISO8859-15", charmap.ISO8859_15)
    52  	tcell.RegisterEncoding("ISO8859-16", charmap.ISO8859_16)
    53  	tcell.RegisterEncoding("ISO8859-2", charmap.ISO8859_2)
    54  	tcell.RegisterEncoding("ISO8859-3", charmap.ISO8859_3)
    55  	tcell.RegisterEncoding("ISO8859-4", charmap.ISO8859_4)
    56  	tcell.RegisterEncoding("ISO8859-5", charmap.ISO8859_5)
    57  	tcell.RegisterEncoding("ISO8859-6", charmap.ISO8859_6)
    58  	tcell.RegisterEncoding("ISO8859-7", charmap.ISO8859_7)
    59  	tcell.RegisterEncoding("ISO8859-8", charmap.ISO8859_8)
    60  	tcell.RegisterEncoding("KOI8-R", charmap.KOI8R)
    61  	tcell.RegisterEncoding("KOI8-U", charmap.KOI8U)
    62  
    63  	// Asian stuff
    64  	tcell.RegisterEncoding("EUC-JP", japanese.EUCJP)
    65  	tcell.RegisterEncoding("SHIFT_JIS", japanese.ShiftJIS)
    66  	tcell.RegisterEncoding("ISO2022JP", japanese.ISO2022JP)
    67  
    68  	tcell.RegisterEncoding("EUC-KR", korean.EUCKR)
    69  
    70  	tcell.RegisterEncoding("GB18030", simplifiedchinese.GB18030)
    71  	tcell.RegisterEncoding("GB2312", simplifiedchinese.HZGB2312)
    72  	tcell.RegisterEncoding("GBK", simplifiedchinese.GBK)
    73  
    74  	tcell.RegisterEncoding("Big5", traditionalchinese.Big5)
    75  
    76  	// Common aliases
    77  	aliases := map[string]string{
    78  		"8859-1":      "ISO8859-1",
    79  		"ISO-8859-1":  "ISO8859-1",
    80  		"8859-13":     "ISO8859-13",
    81  		"ISO-8859-13": "ISO8859-13",
    82  		"8859-14":     "ISO8859-14",
    83  		"ISO-8859-14": "ISO8859-14",
    84  		"8859-15":     "ISO8859-15",
    85  		"ISO-8859-15": "ISO8859-15",
    86  		"8859-16":     "ISO8859-16",
    87  		"ISO-8859-16": "ISO8859-16",
    88  		"8859-2":      "ISO8859-2",
    89  		"ISO-8859-2":  "ISO8859-2",
    90  		"8859-3":      "ISO8859-3",
    91  		"ISO-8859-3":  "ISO8859-3",
    92  		"8859-4":      "ISO8859-4",
    93  		"ISO-8859-4":  "ISO8859-4",
    94  		"8859-5":      "ISO8859-5",
    95  		"ISO-8859-5":  "ISO8859-5",
    96  		"8859-6":      "ISO8859-6",
    97  		"ISO-8859-6":  "ISO8859-6",
    98  		"8859-7":      "ISO8859-7",
    99  		"ISO-8859-7":  "ISO8859-7",
   100  		"8859-8":      "ISO8859-8",
   101  		"ISO-8859-8":  "ISO8859-8",
   102  		"8859-9":      "ISO8859-9",
   103  		"ISO-8859-9":  "ISO8859-9",
   104  
   105  		"SJIS":        "Shift_JIS",
   106  		"EUCJP":       "EUC-JP",
   107  		"2022-JP":     "ISO2022JP",
   108  		"ISO-2022-JP": "ISO2022JP",
   109  
   110  		"EUCKR": "EUC-KR",
   111  
   112  		// ISO646 isn't quite exactly ASCII, but the 1991 IRV
   113  		// (international reference version) is so.  This helps
   114  		// some older systems that may use "646" for POSIX locales.
   115  		"646":    "US-ASCII",
   116  		"ISO646": "US-ASCII",
   117  
   118  		// Other names for UTF-8
   119  		"UTF8": "UTF-8",
   120  	}
   121  	for n, v := range aliases {
   122  		if enc := tcell.GetEncoding(v); enc != nil {
   123  			tcell.RegisterEncoding(n, enc)
   124  		}
   125  	}
   126  }
   127  
   128  func init() {
   129  	registerAll();
   130  }
   131  

View as plain text