github.com/searKing/golang/go@v1.2.117/unicode/casetables.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 ( 8 "unicode" 9 ) 10 11 var Vowels = []rune{ 12 'A', 'E', 'I', 'O', 'U', 13 'a', 'e', 'i', 'o', 'u', 14 } 15 16 var Consonants = []rune{ 17 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', 18 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 19 } 20 21 var VowelCase = func(toUpper, toLower, toTitle func(r rune) rune) unicode.SpecialCase { 22 return SpecialCaseBuilder(toUpper, toLower, toTitle, Vowels...) 23 } 24 25 var ConsonantCase = func(toUpper, toLower, toTitle func(r rune) rune) unicode.SpecialCase { 26 return SpecialCaseBuilder(toUpper, toLower, toTitle, Consonants...) 27 } 28 29 func SpecialCaseBuilder(toUpper, toLower, toTitle func(r rune) rune, points ...rune) unicode.SpecialCase { 30 apply := func(to func(r rune) rune, r rune) rune { 31 if to == nil { 32 return 0 33 } 34 return to(r) - r 35 } 36 var cases unicode.SpecialCase 37 for _, point := range points { 38 cases = append(cases, unicode.CaseRange{ 39 Lo: uint32(point), 40 Hi: uint32(point), 41 Delta: [unicode.MaxCase]rune{ 42 apply(toUpper, point), 43 apply(toLower, point), 44 apply(toTitle, point), 45 }}) 46 } 47 return cases 48 } 49 50 var _AsciiVisual = &unicode.RangeTable{ 51 R16: []unicode.Range16{ 52 {0x0021, 0x007E, 1}, 53 }, 54 LatinOffset: 1, 55 } 56 var ( 57 AsciiVisual = _AsciiVisual // AsciiVisual is the set of Unicode characters with visual character of ascii. 58 )