github.com/searKing/golang/go@v1.2.117/unicode/letter.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package unicode 6 7 import "unicode" 8 9 // IsASCII reports whether the rune is a ASCII character. 10 func IsASCII(s rune) bool { 11 return s < unicode.MaxASCII 12 } 13 14 // IsLatin1 reports whether the rune is a latin1 (ISO-8859-1) character. 15 func IsLatin1(s rune) bool { 16 return s < unicode.MaxLatin1 17 } 18 19 // IsASCIIUpper reports whether the rune is an ASCII and upper case letter. 20 func IsASCIIUpper(r rune) bool { 21 return IsASCII(r) && unicode.IsUpper(r) 22 } 23 24 // IsASCIILower reports whether the rune is an ASCII and lower case letter. 25 func IsASCIILower(r rune) bool { 26 return IsASCII(r) && unicode.IsLower(r) 27 } 28 29 // IsASCIIDigit reports whether the rune is an ASCII and decimal digit. 30 func IsASCIIDigit(r rune) bool { 31 return IsASCII(r) && unicode.IsDigit(r) 32 } 33 34 // IsVowel reports whether the rune is an ASCII and vowel case letter. 35 func IsVowel(s rune) bool { 36 switch unicode.ToUpper(s) { 37 case 'A', 'E', 'I', 'O', 'U': 38 return true 39 default: 40 return false 41 } 42 } 43 44 // IsConsonant reports whether the rune is an ASCII and consonant case letter. 45 func IsConsonant(s rune) bool { 46 switch unicode.ToUpper(s) { 47 case 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z': 48 return true 49 default: 50 return false 51 } 52 }