vitess.io/vitess@v0.16.2/go/mysql/collations/internal/charset/charset.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package charset 18 19 import ( 20 "unicode/utf8" 21 22 "vitess.io/vitess/go/mysql/collations/internal/charset/eightbit" 23 "vitess.io/vitess/go/mysql/collations/internal/charset/japanese" 24 "vitess.io/vitess/go/mysql/collations/internal/charset/korean" 25 "vitess.io/vitess/go/mysql/collations/internal/charset/simplifiedchinese" 26 "vitess.io/vitess/go/mysql/collations/internal/charset/types" 27 "vitess.io/vitess/go/mysql/collations/internal/charset/unicode" 28 ) 29 30 const RuneError = utf8.RuneError 31 32 type Charset = types.Charset 33 34 // 8-bit encodings 35 36 type Charset_8bit = eightbit.Charset_8bit 37 type Charset_binary = eightbit.Charset_binary 38 type Charset_latin1 = eightbit.Charset_latin1 39 type UnicodeMapping = eightbit.UnicodeMapping 40 41 // Unicode encodings 42 43 type Charset_utf8mb3 = unicode.Charset_utf8mb3 44 type Charset_utf8mb4 = unicode.Charset_utf8mb4 45 type Charset_utf16 = unicode.Charset_utf16be 46 type Charset_utf16le = unicode.Charset_utf16le 47 type Charset_ucs2 = unicode.Charset_ucs2 48 type Charset_utf32 = unicode.Charset_utf32 49 50 // Simplified Chinese encodings 51 52 type Charset_gb18030 = simplifiedchinese.Charset_gb18030 53 type Charset_gb2312 = simplifiedchinese.Charset_gb2312 54 55 // Japanese encodings 56 57 type Charset_ujis = japanese.Charset_ujis 58 type Charset_sjis = japanese.Charset_sjis 59 type Charset_cp932 = japanese.Charset_cp932 60 type Charset_eucjpms = japanese.Charset_eucjpms 61 62 // Korean encodings 63 64 type Charset_euckr = korean.Charset_euckr 65 66 func IsMultibyteByName(csname string) bool { 67 switch csname { 68 case "euckr", "gb2312", "sjis", "cp932", "eucjpms", "ujis": 69 return true 70 71 default: 72 return false 73 } 74 } 75 76 func IsUnicode(charset Charset) bool { 77 switch charset.(type) { 78 case Charset_utf8mb3, Charset_utf8mb4: 79 return true 80 case Charset_utf16, Charset_utf16le, Charset_ucs2: 81 return true 82 case Charset_utf32: 83 return true 84 default: 85 return false 86 } 87 } 88 89 func IsUnicodeByName(csname string) bool { 90 switch csname { 91 case "utf8", "utf8mb3", "utf8mb4", "utf16", "utf16le", "ucs2", "utf32": 92 return true 93 default: 94 return false 95 } 96 } 97 98 func IsBackslashSafe(charset Charset) bool { 99 switch charset.(type) { 100 case Charset_sjis, Charset_cp932, Charset_gb18030 /*, Charset_gbk, Charset_big5 */ : 101 return false 102 default: 103 return true 104 } 105 }